2DPlatformer-Tutorial icon indicating copy to clipboard operation
2DPlatformer-Tutorial copied to clipboard

Can I rotate player follow ground?

Open ghost opened this issue 8 years ago • 1 comments

untitled

ghost avatar Mar 08 '17 09:03 ghost

Are you trying to make the player sprite rotate to match the ground, a la Sonic? That's pretty simple:

  1. Put the sprite in its own game object.
  2. Have some component that has a reference to the sprite object's Transform. This can be the Player script, or it could be some other script. For the sake of organization and reuse, I'd create a new component to do this, but that's just one option.
  3. In this component's Update method, have it get the angle of the slope (from collisions.slopeNormal) and write that value over the sprite Transform's eulerAngles.z.
  4. Some extra work will probably be needed to get the sprite to stop floating above slopes with higher angles.

Koopa1018 avatar Feb 11 '18 12:02 Koopa1018