- Home /
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
http://www.youtube.com/watch?v=InlG5bUiRRI
(0:39)
I don't know whether world or player should rotate.
Thanks !
Answer by deltamish · Apr 14, 2013 at 04:07 PM
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
}
}
add this to the object you want to make it rotate left or right
Sometimes it rotates, sometime doesnt And when it rotates player fall through floor within seconds
Your answer
![](https://koobas.hobune.stream/wayback/20220613100315im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Get player to rotate towards object on GetKeyUp 1 Answer
Rotate the Player With Joystick 0 Answers
How do I rotate on World Axes with Quaternion.Slerp? 2 Answers
Rotate to face player, drunk issues 0 Answers