- Home /
Understanding Space.World and Space.Self: Character changing movement direction
Hello, I'm creating a simple platformer and currently I'm stuck on how I would change what direction the player is facing without changing the movement. What i mean by this is when the character moves, I want it to move on the x axis (The character's idle is facing the camera). So when it moves, it faces the direction it is going. So if I were to press left, the player will rotate left and move forward. The issue I'm having is that when the player rotates left, the controls change ( When the player rotates to face left, his axis (what is left/right) to the player changes so therefore pressing left again would mean the player would fall fall (if constraints are off) or not move at all since constraints are on.
if (Input.touches.Length > 0)
{
for (int i = 0; i < Input.touchCount; i++)
{
//setting right touch movement
var touch = Input.GetTouch(i);
if (this.rightController.guiTexture.HitTest(Input.GetTouch(i).position))
{
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if (collisioncheck == true)
{
playerFinder.rigidbody.AddRelativeForce(Vector3.left*10, ForceMode.Acceleration);
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
//clamping players speed
playerFinder.rigidbody.velocity = Vector3.ClampMagnitude(playerFinder.rigidbody.velocity, 10f);
}
else if (collisioncheck == false)
{
//playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
playerFinder.rigidbody.AddRelativeForce(Vector3.left*7, ForceMode.Acceleration);
}
}
}
Answer by bruu · Jan 15, 2014 at 08:24 PM
I have fixed this problem. I used AddRelativeForce instead of AddForce. What AddRelativeForce does is 'Adds a force to the rigidbody relative to its coordinate system' so therefore my characters movement changed.