UEはnodejsを使用してオブジェクトの衝突条件を実装します

(次のコードはアイデアまたは疑似コードを使用していると理解でき、その中で呼び出される UE4 関数またはクラスはすべて実際のものです)

コライダーを設定する

ボックスコリジョン/スフィアコリジョン
let actor = new UE4.Actor();
let box = actor.AddComponent(UE4.BoxComponent);//添加BoxCollision或者SphereCollision
//let extent = actor.getAABB();
//box.SetBoxExtent(extent.halfSize);
box.SetBoxExtent(new UE4.location(1,1,1))//给碰撞盒设置大小
box.SetGenerateOverlapEvents(true);//设置为可触发碰撞事件(重要)
複雑な衝突
let com = actor.GetComponent(UE4.staticMeshComponent);//获取静态网格体组件
com.SetCollisionEnabled(UE4.CollisionMode.QueryAndPhysics);//设置碰撞器触发类型(重要)
com.SetGenerateOverlapEvents(true);//设置为可触发碰撞事件(重要)

コールバックを設定する

世界の重なり合う出来事に耳を傾ける
UE4.World.SetOnActorBeginOverlapCallback(onActorBeginOverlap);
const onActorEndOverlap(overlapActor, otherActor) {
    
    
    //触发碰撞之后实际要执行的代码
}
アクターがコールバック イベントを登録する
const ActorEventType = {
    
    
	/// <summary>
	/// Called when actors start overlapping
	/// </summary>
	OnActorBeginOverlap: 0,
	/// <summary>
	/// Called when actors stop overlapping
	/// </summary>
	OnActorEndOverlap: 1,
	/// <summary>
	/// Called when actors hit collisions
	/// </summary>
	OnActorHit: 2
}
module.exports.ActorEventType = ActorEventType;
UE4.Actor.registerEvent(actor , ActorEventType.OnActorBeginOverlap);

おすすめ

転載: blog.csdn.net/zx1091515459/article/details/125496105