Hi there, Sorry the title seems not very clear because my English is not that good .
I’m new to Unity , and still trying stuff just for test purpose , So My player moves right and left as he supposed to . But when he gets upside down the right becomes left and left becomes the right, so when moving right he goes left and vice versa ; here is my code :
if (Input.touchCount > 0) {
if(Input.GetTouch(0).phase == TouchPhase.Moved)// To know if the player is sliding his/her finger
{
if(Input.GetTouch(0).deltaPosition.x > 0) // is player moving right
transform.Translate(new Vector2(Time.deltaTime *Speed,0));
else if(Input.GetTouch(0).deltaPosition.x < 0) // is player moving left
transform.Translate(new Vector2(- Time.deltaTime *Speed,0));
}
}
( I remember watching the solution on some tutorial back then but can’t figure it out )
How are you turning the character? I’m assuming by rotation. If you look at it in the inspector it is probably flipping the character on the z axis which would put the characters right side on the left of the screen & its left side in the right of the screen so that the movement is correct for the character even though it looks wrong to you.
E.g. If you did a handstand by going forward your right & left would be the same. If you went into a handstand by rolling left or right (half a cart wheel) then everything would be reversed to anyone looking.
You need a way to tell when the player is either “upside right” or “upside down”. Perhaps just a bool like “bool isUpsideDown = false” or something like that, and each update, check if the players z rotation has gone beyond the amount needed to be upside down, and if so, set isUpsideDown to true. Then when your applying your motion to the player, if isUpsideDown is true, you need to instead add the opposite direction of X movement!