- Home /
Question by
TotalPixel · Jul 03, 2014 at 07:25 PM ·
androidtouchtouchscreen
smooth movement with rigidbody2D
Hi all, ive been trying to get this code to work more smoothly.
I have an object that has a force applied to get it to move upwards, and the longer you hold you press the higher it goes and then dropback down when you let go.
It seems to work to a degree but is very jumpy and not smooth at all, any suggestions on where im going worng please?
if (Input.touchCount >= 1)
{
touch = Input.touches [0];
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(jumpForce);
}
else if (touch.phase == TouchPhase.Ended)
{
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(Vector3.up * 0);
}
}
Comment
Best Answer
Answer by arky25 · Jul 03, 2014 at 07:40 PM
Hey, you might want to be using the FixedUpdate function for this, it makes rigidbodys a lot smoother.