First off, I am very new to Unity, but have hobbyist experience with making games.
My problem is a weird one and most likely because I’m not up to speed on how Unity works. I have the following code assigned to my player object:
void Update () {
// Ammount to move
float amtToMoveX = Input.GetAxisRaw("Horizontal") * fPlayerSpeed * Time.deltaTime;
float amtToMoveY = Input.GetAxisRaw("Vertical") * fPlayerSpeed * Time.deltaTime;
// Move the player
transform.Translate(Vector3.right * amtToMoveX);
transform.Translate(Vector3.up * amtToMoveY);
// Rotate player
float angle = Mathf.Atan2(amtToMoveX, amtToMoveY) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.back);
}
My player object is a triangle, and it rotates correctly to the direction of the movement vector. The rotation always works fine.
The player movement works correctly on its own, when I remove the //Rotate player section. They just don’t work well together.
You can see this behaviour at http://www.bigerstaff.com/WebPlayer/WebPlayer.html
All I am trying to do here, is move the player object via Input.GetAxisRaw and point the triangle in that direction. Am I misunderstanding transform.rotation is that also trying to move the player object, even though the player object stays stationary when I remove the //Move the player section?
I hope that makes some sense
Thanks for reading!
David