No announcement yet.

Control collisions

  • Filter
  • Time
  • Show
Clear All
new posts

    Control collisions

    Hi again,

    I have a simple question: How can I control collisions by side??

    Some examples:

    I have the mythical "spyke enemy", and I want it takes live of player only if it's colliding on the top of spyke.
    I have the same situation with destroyable platforms, I want destroy it only if player is colliding on the top with platform.

    Thank you very much for your help!!

    However you are tracking collisions, you should get the HitLocation

    Then, subtract the Location of the Object and the hitLocation to get the relative position where the player hit the object

    so for a spike, if the spike is facing upright toward the sky

    then, when player hits the spike, you can do

    //for a spike that is 220 units tall, and the origin point of spike is its bottom
    if (vsize(HitLocation - spike.Location) > 200){
    This code is saying, if the player hit the spike somewhere on the spike that is within 20 units of the top of the spike, player should take damage.

    If your spike has its origin in the middle, just adjust the numbers accordingly.


    For Objects that have their origins / Locations in odd places within the total mesh

    You can use

    `log("spike hitloc"@HitLocation);
    to see where the player is tending to hit the spots you want


    Obtaining HitLocation

    One way to get hitlocation is the RBCollision event

    See my tutorial on this:

    Rigid Body Collision Events

    in the RB event the hitLocation is called ContactPosition;


    Another solution would be to divide your object into pieces

    so the very tip of the spike, where collisions should count as damage, is made into a separate mesh / object

    and the rest of the spike is a different object

    then you just track whether player collides with the spike tips

    you could even make the spike tips into their own class

    and then when player hits something do a Other.isa('spikeTipClass')

    I prefer my first option of course because it's easier to place spikes when they are only one piece



      Hi evernewjoy,

      Very good post man!! THANK YOU!!
      I'll follow your different ways to control collisions and I'll post you the result.

      Thank you very much evernewjoy!


        Another option is to use the hitnormal value when a player touches the spikes. If they were travelling downwards when the touch occurred then damage them, otherwise don't. That way if they touch the sides of the spikes, they won't get hurt even if they touch the tips, but will if they land on them from above.


          Yet another option is to give the enemy multiple components. The collision event (Bump or Touch) will return which component you collided with. This is also useful for segmented enemies and bosses, weak points, etc.


            Thanks for your help!!

            Neoptolemus: I have controlled the collisions with your way, using HitNormal in bump or touch.

            http404error: How can I give the enemy multiple collision components?? I don't know how I can do that and I think is more interesting feature to learn!!

            Thank you very much!!


              I'm not certain how to do it. Something to do with Skeletal Meshes or something, I would guess? I mean, I think you could give it multiple SkeletalMeshComponents with different names. You should check how UT tests for headshots and such.