0
点赞
收藏
分享

微信扫一扫

碰撞,处理碰撞,发射 Learn Unreal Engine (with C++)


本文使用打砖块游戏举例

碰撞,处理碰撞

碰撞就相当于一个Actor进入另一个Box中,用这个思路就可以处理碰撞了

OnComponentBeginOverlap

当某些内容开始重叠此组件时调用的事件,例如玩家进入触发器。

**委托 事件 **1

AddDynamic( UserObject, FuncName )

用于在动态组播委托上调用AddDynamic()的辅助宏。自动生成函数命名字符串。

当碰撞时

UFUNCTION()
		void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor,
			class UPrimitiveComponent* OtherComp, int32 OtherBodyIndexType, bool bFromSweep,
			const FHitResult& SweepResult);

void ABrick::BeginPlay()
{
	Super::BeginPlay();
	Box_Collision->OnComponentBeginOverlap.AddDynamic(this, &ABrick::OnOverlapBegin);
}

/** 当某对象进入球体组件时调用 */
UFUNCTION()
void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

/** 当某对象离开球体组件时调用 */
UFUNCTION()
void OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

发射

GetBall()->AddForce(FVector(0.0f, 0.0f, 1000.0f), FName(), true);
SM_Ball->AddImpulse(FVector(140.0f, 0.0f, 130.0f), FName(), true);


碰撞,处理碰撞,发射 Learn Unreal Engine (with C++)_虚幻

UPrimitiveComponent::AddImpulse2

给一个刚体增加一个冲量。好一时瞬间爆发

UPrimitiveComponent::AddForce

对单个刚体施加一个力

碰撞,处理碰撞,发射 Learn Unreal Engine (with C++)_ue4_02

  1. 仅使用C++ | 虚幻引擎文档 (unrealengine.com) ↩︎
  2. UPrimitiveComponent::AddImpulse | Unreal Engine Documentation ↩︎



举报

相关推荐

0 条评论