UE4 Collision Overview

1649 篇文章 11 订阅
1623 篇文章 22 订阅

Collision Responses and Trace Responses form the basis for how Unreal Engine 4 handles collision and ray casting during run time. Every object that can collide gets an Object Type and a series of responses that define how it interacts will all other object types. When a collision or overlap event occurs, both (or all) objects involved can be set to affect or be affected by blocking, overlapping, or ignoring each other.

Trace Responses work basically the same way, except the trace (ray cast) itself can be defined as one of the Trace Response types, thusly allowing Actors to either block it or ignore it based on their Trace Responses.

Interactions

There are a few rules to keep in mind with how collisions are handled:

  • Blocking will naturally occur between two (or more) Actors set to Block. However, Simulation Generates Hit Events needs to be enabled to execute Event Hit, which is used in Blueprints, Destructible Actors, Triggers, etc...

  • Setting Actors to Overlap will often look like they Ignore each other, and without Generate Overlap Events, they are essentially the same.

  • For two or more simulating objects to block each other, they both need to be set to block their respective object types.

  • For two or more simulating objects: if one is set to overlap an object, and the second object is set to block the other, the overlap will occur but not the block.

  • Overlap events can be generated even if an object Blocks another, especially if traveling at high speeds.

    • It is not recommended for an object to have both collision and overlap events. Though possible, there is much that needs manual handling.

  • If one object is set to ignore and the other is set to overlap, no overlap events will be fired.

For purposes of testing levels and looking around your worlds:

  • The default Play In Editor camera is a pawn. Thusly can be blocked by anything set to block pawns.

  • The Simulate in Editor camera, before possessing anything, is not a pawn. It can freely clip through everything and will not create any collision or overlap events.

Common Collision Interaction Examples

These interactions assume that all the objects have Collision Enabled set to Collision Enabled so they are set to fully collide with everything. If collision is disabled, it is as if ignore has been set for all Collision Responses.

For the following section, this will be the setup used to explain what is happening:

COL_setup.png

The sphere is a PhysicsBody and the box is WorldDynamic, and by changing their collision settings we can get a number of behaviors.

Collision

By setting both of their collision settings to block each other, you get a collision, great for having objects interact with each other:

COL_collideNoEvent.png

Sphere Collision Setup Wall Collision Setup
COL_collideNoEvent_Sphere.png COL_collideNoEvent_Box.png
In this case, the sphere is a PhysicsBody and it is set to blockWorldDynamic (which is what the wall is). The wall is a WorldDynamic and is set to block PhysicsBodyActors (which is what the sphere is).

In this case, the sphere and the wall will simply collide; no further notifications of the collision will take place.

Collision and Simulation Generates Hit Events

Just collision is useful and in general, the bare minimum for physics interactions, but if you want something to report it has collided so a Blueprint or section of code can be triggered:

COL_collideEvent.png

Sphere Collision Setup Wall Collision Setup
COL_collideEvent_Sphere.png COL_collideNoEvent_Box.png
As in the example above, the sphere is a PhysicsBody and it is set toblock WorldDynamic (which is what the wall is). However, the sphere has also enabled Simulation Generates Hit Events so it will trigger an event for itself whenever it collides with something. The wall is a WorldDynamic and is set to block PhysicsBodyActors (which is what the sphere is). Since the wall is not set toSimulation Generates Hit Events, it will not generate an event for itself.

With the sphere set to Simulation Generates Hit Events, the sphere will tell itself that it has had a collision. It will fire off events such asReceiveHit or OnComponentHit in the sphere's blueprint. Now if the box had an event for collision, it would not fire because it will never notify itself it has happened.

Further, an object that is reporting rigid collisions will report them all and spam reports when it is just sitting on something, so it is best to be careful to filter what it is colliding within its blueprint or in code.

Overlap and Ignore

For all intents and purposes, Overlap and Ignore work exactly the same assuming Generate Overlap Events is disabled. In this case, the sphere is set to overlap or ignore the box:

COL_ignore.png

Sphere Collision Setup Wall Collision Setup
COL_OverlapNoEvent_Sphere.png COL_collideNoEvent_Box.png
Here the sphere is set to overlap WorldDynamic Actors (like our wall), but it does not have Generate Overlap Events enabled. As far as the sphere is concerned, it has not collided or overlapped anything, effectively it has ignored the wall. The wall is a WorldDynamic and is set to block PhysicsBodyActors (which is what the sphere is). As stated above, both Actors need to be set to block each other's respective object types. If they do not, they will not collide.

Or:

Sphere Collision Setup Wall Collision Setup
COL_ignore_sphere.png COL_collideNoEvent_Box.png
Here the sphere is set to ignore WorldDynamicActors (like our wall), and it will pass through the wall. The wall is a WorldDynamic and is set to block PhysicsBody Actors (which is what the sphere is). As stated above, both Actors need to be set to block each other's respective object types. If they do not, they will not collide.

Overlap and Generate Overlap Events

Unlike collisions that can fire every frame, the overlap events are ReceiveBeginOverlap and ReceiveEndOverlap, which only fire in those specific cases.

COL_overlapEvent.png

Sphere Collision Setup Wall Collision Setup
COL_OverlapEvent_Sphere.png COL_collideNoEvent_Box.png
Here the sphere is set to overlap WorldDynamicActors (like our wall), and it will generate an event for itself when it does overlap something. The wall is a WorldDynamic and is set to block PhysicsBody Actors (which is what the sphere is). As stated above, both Actors need to be set to block each other's respective object types. If they do not, they will not collide. But, an Overlap does occur here, and an event for the sphere is fired.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值