Hello Unity Answers, I am trying to create a script to rotate my model as I turn.
I got some code from Here And it works great after changing the rotation to the Y axis except the fact that it returns the rotation to 0, 0, 0. Is there a way I can edit it to where the return position is 0, 90, 0? I tried adding an if statement for turning the model then an else statement to set it to 0, 90, 0
Edit: Here is the code I have, it’s essentially the same as linked above
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
void Update() {
float tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
Quaternion target = Quaternion.Euler(0, TiltAroundY, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
Hi, ok this is a quick answer but this is significant.
“Quaternion target = Quaternion.Euler(0, TiltAroundY, 0);”
moghes
3
try this,
//or use a FixedUpdate
void Update ()
{
private float horiz = Input.GetAxis("Horizontal") * tiltAngle;
transform.Rotate(new Vector3(0,horiz ,0), Space.Self);
}
Add 90 degrees to default angle: Quaternion.Euler(0, tiltAroundY +90, 0);
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
void Update() {
float tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
Quaternion target = Quaternion.Euler(0, tiltAroundY +90, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
…or make empty gameobject as parent and current gameobject as child with (0,90,0) rotation. Rotate parent.