- Home /
How to move rigidbody a certain distance, rather than constantly
`rb2d.MovePosition(rb2D.position + velocity * Time.fixedDeltaTime);`
will move the player constantly. However, I would like the player to move a certain distance in a certain direction when the left arrow key is pressed, as if they have teleported to the new position. I can do it with transform.translate, but this means it won't work with collisions. Any idea how I can do this with Rigidbody2d.MovePosition? ?
I have tried:
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
rb2D.MovePosition(rb2D.position + velocity * Time.fixedDeltaTime);
}
But that doesn't result in movement
Thanks!
Comment
Answer by MrCreator97 · Nov 14, 2016 at 07:35 AM
Drop the Time.fixedDeltaTime, that is interpolating the distance between the frames so it moves smooth,ly however, for you case, you don't need it. See if that works :)
(Edit) Here :
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
rb2D.MovePosition(rb2D.position + velocity);
}