Rotating world/player

Hi guys, I need some help with rotating world/player in 3D game. I want to rotate world/player for 90 deegres on specific axis when specific key is pressed. For example when I press Left Arrow key world/player should rotate 90 degrees to the left. I’m trying to make something like this

(0:39)

I don’t know whether world or player should rotate.

Thanks !

1 Answer

1

Hi try using this script

public var Rotatevalue:float = 90;
public var Rotatespeed:float = 2;
private var Horizontal:float;//horizontal axis
function Update(){
Horizontal = Input.GetAxis("Horizontal");
if(Horizontal>0.1){
transform.rotation.y = Mathf.Lerp(transform.rotation.y,Rotatevalue,Time.deltaTime * Rotatespeed);//rotate on y axis upto 90 deg
}
if(Horizontal <-0.1){
transform.rotation.y = Mathf.Lerp(transform.rotation.y,-Rotatevalue,Time.deltaTime * Rotatespeed);//rotate on y axis upto -90 deg
}
}

Where does it go ?

–

add this to the object you want to make it rotate left or right

–

Not really helpful, but thanks for trying :)

–

why what are the problems you are facing

–

Sometimes it rotates, sometime doesnt And when it rotates player fall through floor within seconds

–