基于C++代码的UE4学习(二)—— 碰撞体

 

在Unreal Engine中简单的碰撞体分为box,sphere和capsule。

今天以box碰撞体举例,其他的俩种构建方法都是相同的。

构建box碰撞体需要#include "Components\BoxComponent.h"头文件,记得导入

这是头文件,通过UBoxComponent类来定义box类型的碰撞体。

 

 1 UCLASS()
 2 class STANDARDDELEGATE_API ATriggerActor : public AActor
 3 {
 4     GENERATED_BODY()
 5     
 6 public:    
 7     // Sets default values for this actor's properties
 8     ATriggerActor();
 9 
10 protected:
11     // Called when the game starts or when spawned
12     virtual void BeginPlay() override;
13 
14 public:    
15     // Called every frame
16     virtual void Tick(float DeltaTime) override;
17 
18 public:
19     UPROPERTY()
20     class UBoxComponent* box;
21 };

 

 

这是源文件

 

1 ATriggerActor::ATriggerActor()
2 {
3      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
4     PrimaryActorTick.bCanEverTick = true;
5     box = CreateDefaultSubobject<UBoxComponent>(TEXT("box"));
6     box->InitBoxExtent(FVector(50.0f));
7 }

 

通过CreateDefaultSubobject方法来创建UBoxComponent类的对象。

并使用InitBoxExtent(FVector())方法来设置碰撞体的大小。

 

编译后,碰撞体就生成了。

 

 

 

 

将该对象拖入关卡中,就可有看见一个碰撞体出现了:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值