No announcement yet.

How to Obtain Vector Normal and Point Collision Data of KActors/Static Meshes

  • Filter
  • Time
  • Show
Clear All
new posts

    How to Obtain Vector Normal and Point Collision Data of KActors/Static Meshes

    Dear Community,

    Here is way to gather each point of collision between two rigid bodies, (RB Physics)

    such as Kactors even the primitive components of any static mesh.

    You can also retrieve the NORMAL data.

    I could not get the Touch, Bump, or HitWall Events to work for my KActor ball so I used the RB Event instead.

    ACTOR Event Rigid Body Collison

    I gathered this code as I was researching how to make a KActor ball go around a 360 degree loop.

    You can use this code to:

    1. determine all points of contact between two colliding Actors who have RB physics components (rolling ball for example)

    2. determine the hit normals of the contacts, so you can create a rebounding effect or additional gravity force to push a KActor against another curved surface of a larger static mesh.

    3. this data is gathered per-contact during the game time, as it is an EVENT function

    4. The actor that was collided with (as well as the actor triggering the Collision Event)

    If you are defining your own static mesh component you should use this code:

    	//if having performance issues try removing this
    	Begin Object class=DynamicLightEnvironmentComponent Name=joyLightEnv
    		bEnabled = true
    		bCastShadows = false 					//false
    	End Object
    	Begin Object Name=StaticMeshComponent0
    		CastShadow = false						//false
    		//RB Collision
    		bNotifyRigidBodyCollision = true
    		ScriptRigidBodyCollisionThreshold = 1
    	End Object
    	bCollideActors = true

    If you are simply using an existing KActor made in the UDK editor or generated via unrealscript, use the following code on the KActor you want to gather the collision info for:

    Simulated Event PostBeginPlay() {
    	//make sure bNotifyRigidBodyCollision is set to true in UDK editor
    	Self.StaticMeshComponent.ScriptRigidBodyCollisionThreshold = 1;

    Background information for the code below, Explains the Data Structures Involved:


    Drawing the Normal from a Surface Point of Contact

    This code draws a visual line representing the normal / the line that is perpendicular to the surface point of contact between your KActor / rigid body and the surface of the mesh/actor it is hitting in-game

    Here is the EVENT function you put in your KActor or other Rigid Body / Static Mesh class so you get info each time your Rigid Body collides with something:

    var Actor collidedActor;
    event RigidBodyCollision (	PrimitiveComponent HitComponent, 
    					PrimitiveComponent OtherComponent, 
    					const out CollisionImpactData RigidCollisionData, 
    					int ContactIndex) 
    	local RigidBodyContactInfo r;
    	local vector v;
    	r = RigidCollisionData.ContactInfos[0]; //see the background info links above
    	v = r.ContactNormal; 
            //the actor that this object collided with
            collidedActor = OtherComponent.Owner;
    	//draws a blue line indicating the normal to the surface point of contact
            //of Actor's rigid body and the rigid body it is colliding with.
            //r.ContactPosition is the point of contact, see the background info reference pages
    	Self.DrawDebugLine(r.ContactPosition, r.ContactPosition + v  * 700, 0, 0, 255, true);