List

As you may know, a lot of the interactivity from games comes from the ability to have objects interact with each other. One of the simplest things you can do to give players agency in your world is by allowing them to interact with it, like losing health if they hit a trap. This is simple enough to do inside of UnrealEd (the level editor), but working with collision in Unrealscript happens to be a very confusing thing for most newcomers. There seems to be so many functions that are used in a lot of different occasions.

The following is my attempt to make this a little easier for those looking to do something involving collision inside of UnrealScript and dispel some of the issues that I see students having.

Actor Class Properties Related to Collision

Actor classes (and those that extend from it) have a number of properties related to collision. They handle how all of the collision detection, responses as well as simulation will be handled by the engine on these actors. Note that I am not mentioning all of these (see this for that) but merely the ones that I use on a normal basis:

bBlockActors: If true, the Unreal engine will not allow the two Actors to overlap.
bCollideActors : If false, the actor does not collide or block anything.

Depending on how you want your object to collide, you may have these set to different things. A trigger for example would have bCollideActors set to true, but bBlockActors set to false. This is because the desired effect is for Unreal to detect when the two Actors touch each other, but for the moving Actor to move through it.

bCollideWorld : whether or not the object will collide with the level geometry (CSG) in the level

bCollideWorld is a special case, but any time that an actor collides with World Geometry it will call the HitWall function, which we will talk about later.

bCollideComplex: If true, the object will collide based off of each polygon on the object instead of the simplified collision mesh mentioned above. This is the most expensive toggle time-wise.
bNoEncroachCheck: Can the actor touch triggers, push player, or actually enter or exit volumes
BlockRigidBody: If KActors should collide against this actor.

Do note that the collision component that the object will use is relative to the physics property currently being set to it. For example, if the Actor is using PHYS_Walking, then the axis aligned bounding box of this component will be collided against the level. If the Actor is using PHYS_RigidBody, then the shape or physics asset of this component is used.

UnrealScript Events

When collisions occur in UDK, different events/functions are called based off of the properties that the Actors have. There are a lot of them, but the ones I most often use are:

HitWall

HitWall is called when the Actor has collided into a Wall and/or level geometry as long as bCollideWorld is true.

event HitWall(Vector HitNormal, Actor Wall, PrimitiveComponent WallComp)

HitNormal :        Normal that the Actor hit the wall with.
Wall :                    Actor that self is colliding with.  If the Wall is CSG, Wall is set to WorldInfo.
WallComp:         Component that this Actor colliding into. When CSG, WallComp is set to None.

One thing to note is that a Pawn or Pawn’s Controller may change whether HitWall will actually be called:

In the Pawn class if bDirectHitWall is set true, then it will only call the pawn’s HitWall event .

The Controller classes also have a function called NotifyHitWall. If that function returns true, then HitWall will not be called.

Touch

This event is called when two Actors are overlapping; however it will only be called if both actors have bCollideActors set to true and only one of the Actors has bBlockActors set to false. This function will be called every game loop that the collision is still occurring (during the Tick)

event Touch(Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal);

Other :                 Actor that touched this Actor.
OtherComp :      Component that touched this Actor.
HitLocation :      World location where the touch occurred.
HitNormal :        Normal of the touch that occurred.

Untouch

UnTouch is called whenever an actor that was touching something is no longer doing it. Again, the same requirements for Touch are true here as well in the fact that that both actors need to have bCollideActors set to true and only one of them has bBlockActors set to false. That being said, the function is only called once when the collision is no longer occurring.

event UnTouch(Actor Other)

Other : The actor that has just been untouched.

Bump

This event is called when two Actors are bumping into each other, but it will only happen if the two Actors have the bBlockActors property set to true. This will only be called once, at the start of the collision

event Bump(Actor Other, PrimitiveComponent OtherComp, Vector HitNormal);

Other :                  Actor that bumped into this Actor.
OtherComp :      Component that bumped into this Actor.
HitNormal :        Normal of the bump that occurred.

To help explain what functions will be called when, I made a table which may help (1 means it will be called, 0 means it won’t):

Abridged Collision Functions Table

bCollideActors

bBlockActors

 

Self

Other

Self

Other

Functions Enabled

1

1

1

1

Self gets Bump, Other gets Bump

1

1

1

0

Self gets Bump, Other gets Touch

1

1

0

1

Self gets Touch, Other gets Bump

1

1

0

0

None


Do note the special case where if one object has bCollideActors set to true and the other has bBlockActors, the object being bumped (the bCollideActors object) will get a Bump() event while the other will simply get a Touch() call.

Conclusion

So hopefully that helped to dispel some of the initial confusion. I know there are a lot of special cases, but by trying each of these types out and experimenting with them, you’ll be up and going in no time!


 

 

  Posts

1 2 3 5
December 7th, 2017

Unity 2017 Tilemap Tutorial

Content creation is one the most time-consuming aspects of game development. One way you can design levels quicker and easier […]

January 7th, 2017

Visual;Conference 2017

As a part of Visual;Conference 2017, I was invited to give a talk on Game Engines for the development of […]

November 11th, 2014

Unity Game Development Blueprints Released!

My fifth title, and first Unity title, is now out! In this book I took feedback from my previous books […]

May 6th, 2014

Video Series UDK Game Development Released!

My fourth title published by Packt is now out! Unlike previous entries this is a video series and delves into […]

December 17th, 2013

Benefits and drawbacks of using Kismet

As with any job it is important to use the tool that is appropriate for it. UDK provides three ways […]

November 20th, 2013

Types of Collision in UDK

As you may know, a lot of the interactivity from games comes from the ability to have objects interact with […]

August 19th, 2013

Guest appearance on CrunchCast

Recently I had the privilege to talk to Chris Holden on CrunchCast about myself, my books, and Unreal in general. […]

August 18th, 2013

Getting Started with UDK – UnrealScript

This post will be the most useful for those who have already read or are currently reading my latest book, […]

June 8th, 2013

Flash 101: An Introduction

As you begin your project, there may be many new panels and areas that are yours to use.   Stage […]

June 8th, 2013

Setting up Flash CS6 to use Scaleform with UDK

Currently, I am in the middle of writing my third book with Packt Publishing, this book on creating a single project over […]