I am trying to modify my characters rotation using this method:
The problem is, when I run my game, a Player(Clone) is created as a separate game object in a different location, and with a different rotation (than the one I applied to my empty parent object). Even worse is when I enable my Player object to be viewable, I can see that he is facing the right way, but once I go to move he reverts back to facing the incorrect way -_-
Anyone have any clues as to what may be going on?
Here is my C# script that Instantiates the Player
public GameObject player;
private void SpawnPlayer()
{
//Sets player as Camera's target
cam.SetTarget((Instantiate (player, Vector3.zero, Quaternion.identity) as GameObject).transform);}
Just in case anyone comes across this with a similar problem, here was my solution.
In my PlayerController script, I was controlling movement as such
if (moveDirection != 0)
{
transform.eulerAngles = (moveDirection > 0) ? Vector3.up * 180 : Vector3.zero;//If move direction is greater than zero than we flip our char to be facing the right way
}
This was not working for me, as my character would go from facing forward to facing backwards.
You don’t need tow nested if statements (in your answer); if moveDirection == -1 it will definitely be less than 0, and vice versa. Also if you need to move about an axis then there is RotateAround, see here. Where you can just do transform.RotateAround(transform.position, Vector3.up, (moveDirection > 0) ? 90 : -90), when moveDirection != 0.