0

Having an issue with farseer physics im pretty sure the issue is just with this line of code because of the y value. So when i try to move my character when falling he moves left and right normally but his fall slows.

body.LinearVelocity = new Vector2(1,0)

Is there a way to only change the x value of this? Or is there a way to prevent sliding and set a cap on the speed of applyforce() or applylinearimpulse()?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
KGSB
  • 39
  • 7

1 Answers1

1

By setting the linear velocity to 1,0 you give the character a horizontal speed of 1 and a vertical speed of 0. So you effectively stop it from falling.

The following code will do what you would expect as it preserves the vertical speed.

body.LinearVelocity = new Vector2(1, body.LinearVelocity.y);

In some (most) cases it is better to apply a force or impulse to the character using body.Apply... this applies a force for a single frame and Farseer will automatically compute the correct velocity. Note that adding the same force or impulse every frame will make the movement speed-up.

Roy T.
  • 9,429
  • 2
  • 48
  • 70
  • It doesn't stop the movement on the y-axis. I know that it should i guess te devs for farseer physics dont think so. Thanks for the help – KGSB Oct 09 '14 at 23:31
  • It stops the movement calculated so far. But then at the final step the force of gravity is applied. So thats why it slows down instead of stop totally :). – Roy T. Oct 10 '14 at 09:45