Search Unity

Making an object rotate around itself while moving around.

Discussion in 'Scripting' started by rjdfhorn2006, May 7, 2016.

  1. rjdfhorn2006

    rjdfhorn2006

    Joined:
    Jun 14, 2010
    Posts:
    141
    I'm currently working on a game that involves swimming. When the player isn't pressing anything, the character is in a neutral resting/floating position (the character is floating upright). When I press the W (forward) button, the character starts to swim. I'm trying to figure out how to make the character perform a slerp rotation to rotate 90 degrees around its x axis so they become horizontal (swimming forward).

    How would you go about making a character rotate only 90 degrees (with a slerp) from an upright position independent of which direction they're facing? I would prefer to use Rigidbody.MoveRotation (since my other code uses that function - this is for a platformer game).