Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Velocity on rigidbody keeps going sometimes

What I'm confused about is in the code, in update, I said if (MyTransform.position.x >= -2f) but it keeps going until -1.8 and sometimes it keeps going to -1.25.

Best Answer

  • ZicrusZicrus Member
    Accepted Answer

    It only checks once every frame, so on the first frame it can be at -2.1 and then on the next it maybe moves 0.5, which puts it at -1.6. Then it checks, and stops moving. To fix this, you need to calculate if it will move too far. if it will, move it to the desired position (-2) and stop the velocity.


  • BarjiBarji Member

    (MyTransform.position.x >= -2f) I think you mean "<=" -1.8 IS greater than -2, as is -1.25

Sign In or Register to comment.