- Home /
Question by
FakeDonaldTrump · Jul 07, 2017 at 01:10 PM ·
unity 5movementmovement script
Left and right is inverted when moving!
i dont get any errors! Here is the code:
private float speed = 8f;
private float jumpforce = 100f;
private float gravity = 190f;
private Vector3 moveDir = Vector3.zero;
// Use this for initialization
void Start()
{
}
// Update is called once per frame Horizontal
void Update ()
{
CharacterController Controller = gameObject.GetComponent<CharacterController>();
moveDir = new Vector3(Input.GetAxisRaw("Vertical"), 0, Input.GetAxisRaw("Horizontal"));
moveDir = transform.TransformDirection(moveDir);
moveDir *= speed;
if (Input.GetButtonDown("Jump") && Controller.isGrounded)
{
moveDir.y = jumpforce;
}
moveDir.y -= gravity * Time.deltaTime;
Controller.Move(moveDir * Time.deltaTime);
}
}
Comment
Answer by tanoshimi · Jul 07, 2017 at 01:39 PM
Vector3s are always represented in X, Y, Z order. So I'm guessing you meant:
moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if i switch them w and s is left and right and a and d is backwards and forwards...
Answer by TimothyAppel · Jul 10, 2017 at 09:26 PM
Go to edit > project settings > input and expand the horizontal axis and them select invert, this will switch left and right around.
Your answer
Follow this Question
Related Questions
Dampening Movement while in the Air 0 Answers
2D player keeps getting dragged to the left for some reason. 0 Answers
How do I stop my character from moving in a circle upon destination arrival? 1 Answer
Character rotation and move to mouse click point with speed 0 Answers
Moving tram along rail. 0 Answers