Hello. Im wanting a way to give a physics body a speed boost while keeping its direction the same. I thought I could use the Get linear velocity functions with applyForce to achieve this effect but Im confused as what getLinearVelocityfromWorld/LocalPoint does and which should I use?
@Goatboy76 Don’t know if you’ve figured this out but I’ll take a stab at answering your questions. Firstly, if you want to apply more speed in the current movement direction, you can normalize the linear velocity, multiply it by the amount of speed you want to add, and apply it as force:
-- warning: I haven't tested this, but I think it's right. -- doing this once will increase the body's speed by 10 pixels/second -- in the direction it is already moving local speedToAdd = 10 local lv = body.linearVelocity if not (lv.x == 0 and lv.y == 0) then local force = lv:normalize() * speedToAdd * (1 / DeltaTime) body:applyForce(force) end
As for the second part:
getLinearVelocityFromLocalPoint return the velocity of a body at a specific point relative to the body (this is helpful, because it factors in the body’s angular velocity as well). The body’s
linearVelocity property yields the same result as calling