文档章节

COLLISION FILTERING

2steper
 2steper
发布于 2016/05/27 12:14
字数 989
阅读 41
收藏 0

Choosing what collides is obviously very important, but it can be tricky, and it’s a problem that we have spent quite a while discussing while developing UE4. The system we have can seem a little complex at first, but it is very powerful and consistent, so I wanted to give a little background on how we arrived at it. We’ll talk about the different responses to collision, how we use channels to filter collisions, and outline the difference between simple and complex collision geometry.

BLOCKING, OVERLAPPING AND IGNORING

The first thing to know is that when you say something should collide, you have to choose whether you can penetrate it or not. A brick wall will ‘Block’ a player, but a trigger will ‘Overlap’ them, allowing them to pass through. Both generate an event (‘Hit’ or ‘Overlap’ respectively, in UE4 terminology) but it is an important difference*. Other objects may ‘Ignore’ the collision altogether, giving us our three response types.

TRACE CHANNELS AND OBJECT CHANNELS

The next big question at the heart of collision filtering is “who gets to choose?” Is it the object that decides what types of query to collide with? Or does the query decide what types of object it is looking for? In different scenarios they both make sense, so UE4 supports both!

Imagine we define two ‘Trace Channels’ in our game, one for ‘Visibility’ and one for ‘Weapon’ queries. A brick wall is set up to block both, a shrub blocks visibility but not weapons, and bulletproof glass blocks weapons but not visibility. When you do this kind of query you specify a single Trace Channel.

TraceExample

If I changed this around so the game code had to know what types of object to query for, our game could need a huge number of different types to handle all these situations! It also allows us to make ‘spot fixes’ in content later on, instead of changing the calling code itself and possibly breaking other things.

There are however some situations where you do want to query for objects based purely on their type, and this is where we use ‘Object Channels’. One example is an explosion going off, and you want to quickly find all objects of type ‘Pawn’ or ‘PhysicsBody’ within a certain radius. When you do this kind of query, you can specify multiple Object Channels.

UE4 has a few ‘built in’ Trace Channels (Visibility, Camera) and Object Channels (WorldStatic, WorldDynamic, Pawn, PhysicsBody, Vehicle, Destructible), but you can easily add your own under Edit -> Project Settings -> Collision, though you are limited to 32 in total.

COLLISIONS BETWEEN MOVING OBJECTS

Things get a bit more complicated when you want to handle collisions between moving objects, because there can be so many combinations. In UE4 each object knows its own Object Channel, plus a list of how it responds to other Object Channels. When two objects intersect, we look at how they respond to each other, and take the least blocking interaction, like so:

Filter Table

So imagine the following scene:

Object Example 1

Now the player moves forward. First he will overlap the shrub. The Player is of type Pawn, and the Shrub wants to Overlap that. The Shrub is of type WorldStatic, and the Player wants to Block that. Checking the chart, the final result is Overlap! Similarly the Brick Wall and Player both want to Block each other, so the player walks through the Shrub (generating an Overlap event) and is stopped by the wall (generating a Hit event).

Object Example 2

If you had two players and one wanted to become ‘ghostly’, he could change his response to the Pawn channel from Block to Ignore, and then he could walk right through other players.

COLLISION PRESETS

Even though this system gives a lot of control over what objects in your level will collide with, in practice most objects fall into common configurations. To make things easier, UE4 has a ‘Collision Preset’ system. Each Preset contains an Object Type, and a response to each Trace and Object Channel in your game. When you select an object in the level, you will see a simple dropdown, allowing you to select a Preset:

Collision

UE4 has several of these built in (e.g. Invisible Wall, Physics Actor etc), and again you can create your own inside Project Settings. If you don’t want to use a Preset, you can choose ‘Custom…’ and then you can modify every response, liked we talked about above:

Collision UI

SIMPLE AND COMPLEX COLLISION

One final thing to understand is that each object in UE4 can have both a ‘complex’ and ‘simple’ collision representation. Complex Collision refers to using the actual rendering geometry for collision. This is most useful for things like weapon traces, where you want to be able to shoot exactly what you see. You don’t always want to collide with this though, and so each mesh can also have a Simple Collision representation consisting of a collection of spheres, boxes, capsules and convex hulls. When you perform a collision query, you tell UE4 what kind of geometry you want to collide with. Player movement, for example, collides against simple geometry, to avoid getting ‘stuck’ on little details.

In the editor there is a handy View Mode that lets you see the world as a player will collide with it:

Collision Mode 1Collision mode 2

CONCLUSION

So that is the whole, heady world of collision filtering in UE4! I hope it was helpful to understand some of the problems we are trying to solve and how to make use of it for your own game. Any questions or comments? We’re always over in the forums or you can hit me up on Twitter at @EpicJamesG.

--

*We can actually stop looking for collisions after the first blocking collision, which is a good performance optimization - imagine firing a gun with a range of 1km at a brick wall 1m in front of you, we just skipped 999 meters of work!

本文转载自:https://www.unrealengine.com/blog/collision-filtering?lang=en-US

2steper
粉丝 2
博文 15
码字总数 2773
作品 0
榆林
高级程序员
私信 提问
Docker v1.12.2-rc3 发布,内置编排机制

Docker v1.12.2-rc3 发布了。 改进内容: Runtime Fix a panic due to a race condition filtering #26049 Implement retry logic to prevent "Unable to remove filesystem" errors when us......

达尔文
2016/10/08
880
1
Laravel 5.6 为命令行错误报告添加了 collision 包

由 nunomaduro 创建和维护的 是PHP命令行应用程序的错误处理程序包。从Laravel 5.6开始,应用程序将包含 Collision 软件包的 composer 依赖。 当通过命令行或CLI与Laravel应用程序进行交互时...

如来神掌
2018/04/28
38
0
常见的以太网错误帧类型

以太网的传输并非百分之百可靠,数据帧传输过程中可能出错。下面列出了常见的以太网错误帧类型: 1) CRC错误帧 CRC错误较为常见。数据帧传输过程中,某些比特位可能会从0变为1或者从1变为0。...

cafe007
2014/03/30
0
0
从零开始学虚幻4游戏开发系列07

在上一课的内容中,我们成功的实现了让玩家角色可以在游戏场景中自由移动。但是如果你仔细观察,会发现代表玩家角色的方块可以穿越所遇到的一切障碍,显然这是不科学的~ 为此,我们需要了解C...

王寒
2017/12/21
0
0
unity3d中的trigger和collision消息以及刚体与碰撞体

一直困惑于unity3d中的触发和碰撞消息在什么条件下能够发生,平时用时也是一知半解。磨刀不误砍柴工,是时候发点时间一劳永逸的解决这个问题了XD。 OnTriggerEnter, OnTriggerStay, OnTrigg...

crydonkey
2015/02/13
4.5K
0

没有更多内容

加载失败,请刷新页面

加载更多

关于AsyncTask的onPostExcute方法是否会在Activity重建过程中调用的问题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/XG1057415595/article/details/86774575 假设下面一种情况...

shzwork
今天
7
0
object 类中有哪些方法?

getClass(): 获取运行时类的对象 equals():判断其他对象是否与此对象相等 hashcode():返回该对象的哈希码值 toString():返回该对象的字符串表示 clone(): 创建并返此对象的一个副本 wait...

happywe
今天
6
0
Docker容器实战(七) - 容器中进程视野下的文件系统

前两文中,讲了Linux容器最基础的两种技术 Namespace 作用是“隔离”,它让应用进程只能看到该Namespace内的“世界” Cgroups 作用是“限制”,它给这个“世界”围上了一圈看不见的墙 这么一...

JavaEdge
今天
8
0
文件访问和共享的方法介绍

在上一篇文章中,你了解到文件有三个不同的权限集。拥有该文件的用户有一个集合,拥有该文件的组的成员有一个集合,然后最终一个集合适用于其他所有人。在长列表(ls -l)中这些权限使用符号...

老孟的Linux私房菜
今天
7
0
面试套路题目

作者:抱紧超越小姐姐 链接:https://www.nowcoder.com/discuss/309292?type=3 来源:牛客网 面试时候的潜台词 抱紧超越小姐姐 编辑于 2019-10-15 16:14:56APP内打开赞 3 | 收藏 4 | 回复24 ...

MtrS
今天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部