Search Unity

Making an enemy drop down from ceiling and rotating

Discussion in 'Getting Started' started by Woodpig, Jun 11, 2017.

  1. Woodpig

    Woodpig

    Joined:
    Apr 7, 2017
    Posts:
    2
    I'm making a 2D platformer and I want to have some enemies dropping down from the ceiling.

    I've made it so that an enemy is sitting upside down at the roof, casting a ray down to the ground and dropping (by adding gravity) when the player is right below it, which is all good, but I also want the enemy to rotate exactly 180 degrees smoothly and land on his feet.

    I've tried experimenting with different float values to make the enemy rotate 180 degrees, and although it works sometimes, it's never very precise. It needs to be exact.

    Oh yeah. I'm using a Rigidbody2D component for the enemy to be able to jump and chase the player once he's landed.

    Would be very thankful if somebody had the answer for this. Thanks a bunch for reading. :)
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Just thinking out loud here, but what if you used the distance from the enemy to the ground as a variable for Slerp'ing the rotation as it falls.
    Example: I'm 4m from the ground, and I'm falling, after 1m I should be 45degrees switched.
    1/4 = .25f <- slerp parameter.
    Sounds logical to me ;) What do you think?