I’m new to this thread and unity, so sorry if this is in the wrong section or if my question is very obvious.
I have started to make a space shooter game in unity 2d for android. I’ve made my ship move right and left, when touching the right side or the left side of the screen respectively (The rigidbody2d is kinematic, hence why I’m using moveposition). However, when I press the screen and let go, the object does not stop moving until a few moments later.
Here is the code that i have used:
private Rigidbody2D rb2d;
public float moveRate = 0.1f;
void Start () {
rb2d = GetComponent<Rigidbody2D> ();
}
void Update () {
foreach (Touch touch in Input.touches) {
if (touch.position.x < Screen.width/2) {
rb2d.MovePosition(rb2d.position - new Vector2(moveRate, 0) * Time.fixedDeltaTime);
}
else if (touch.position.x > Screen.width/2) {
rb2d.MovePosition(rb2d.position + new Vector2(moveRate, 0) * Time.fixedDeltaTime);
}
}
}