Question by
Equ1l1brist · Feb 03, 2017 at 04:29 PM ·
rotationquaternionteleportmethodkeypress
Rotation working within an if statement but not within a method???
Hello, I have a piece of code within an if statement and which works fine, but when I use the exact same piece of code within a method being called it won't work at all. Could anyone explain why this is happening? Also, if you have any better recommendations for rotating the player 180 degrees after a collision and on a keypress I'd be happy to see them.
public class PlayerEvents : MonoBehaviour {
public void TeleportPlayerTo(Vector3 _telePosition) {
//Positional change works fine
transform.position = _telePosition;
print("Called");
//This section doesn't seem to work when called within a method
Vector3 rot = transform.rotation.eulerAngles;
rot = new Vector3(rot.x, rot.y + 180, rot.z);
transform.rotation = Quaternion.Euler(rot);
}
void Update() {
//Whereas it works fine within a keypress
if (Input.GetKeyDown(KeyCode.R)) {
Do180();
}
}
public void Do180(){
Vector3 rot = transform.rotation.eulerAngles;
rot = new Vector3(rot.x, rot.y + 180, rot.z);
transform.rotation = Quaternion.Euler(rot);
}
}
Comment