Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Uneven speed in 2d movement script

$
0
0
I have a very simple 2d game so far and im working on the movement. for some reason my a (left) is much slower than my d (right). Does anyone know why this happens? Also, should i include a forcemode2d? Thanks a lot, heres my code using UnityEngine; public class Movement : MonoBehaviour { public float Speed; public Rigidbody2D Rb; public SpriteRenderer SpriteRen; public Sprite PlayerR; public Sprite PlayerL; public Vector2 Coords = new Vector2(1, 1); void Start() { Rb = GetComponent(); SpriteRen = GetComponent(); } void FixedUpdate () { if (Input.GetKey("a")) { Rb.AddForce(Coords * -Speed); SpriteRen.sprite = PlayerL; } if (Input.GetKey("d")) { Rb.AddForce(Coords * Speed); SpriteRen.sprite = PlayerR; } } }

Viewing all articles
Browse latest Browse all 1264

Latest Images

Trending Articles