I’m doing some very simple movement. I have a character that is standing in the middle of a scene. If the user swipes to the right, the character moves to the right until he hits an obstacle.
When I test this in the Unity editor, all movement works fine. I just call Move() on the CharacterController and pass it the movement vector (which is either Vector.forward/.back/.right/.left).
But when I run it on my iOS device, it is as if the movement vector is relative to the camera location instead of the character. For example, if I call Move(Vector.forward), the character moves up into the air instead of “forward” in the scene.
Does this make sense? What am I missing? Here is some code:
CharacterController controller = GetComponent<CharacterController>();
float dX = Mathf.Abs(touchPosition.x - startTouchPosition.x);
float dY = Mathf.Abs (touchPosition.y - startTouchPosition.y);
if (dX > dY)
{
if (touchPosition.x > startTouchPosition.x)
controller.Move(Vector3.right * Time.deltaTime);
else// if (touchPosition.x < startTouchPosition.x)
controller.Move(Vector3.left * Time.deltaTime);
}
etc...