UE4 COLLISION FILTERING
2015-10-15 15:17
507 查看
COLLISION FILTERING
James Golding on April 18, 2014 | Design Features LearningShare on Facebook
Share on Twitter
Share on Google+
Share on LinkedIn
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, allowingthem 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 bothmake 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.
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. Whentwo objects intersect, we look at how they respond to each other, and take the least blocking interaction, like so:
So imagine the following scene:
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).
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 Presetcontains 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:
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:
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 forthings 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:
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 oryou 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!
相关文章推荐
- 接触UI
- UE4 Collision Response Reference
- Munzekonza_random_forestinstallation guide
- UE4 Collision Overview
- 在Event内部监测鼠标事件,对窗体内控件调用move动作,UI不刷新
- 限制UITextField只可以输入数字
- request.getRequestURI() 、request.getRequestURL()
- Java Map Key-Value
- request.getRequestURI() 、request.getRequestURL()
- 常用的交互设计软件
- Interface Builder操作
- 【IOS 开发学习总结-OC-50】★ios开发之UI控件——UIToolBar(工具栏)
- Android漂亮UI合集(From:github)
- 30 Java Exception Handling Interview Questions And Answers
- 25 Java Array Interview Questions And Answers
- EasyUI - datagrid中单元格里编辑控件的单击事件如何获取当前行的index
- iOS 基础-----关于UIView 的 frame 与 bounds
- UINavigationController + UIScrollView组合,视图尺寸的设置探秘(二)
- UIScrollView代理方法执行顺序
- 使用 RequireJS 优化 Web 应用前端