Hi. Trying to make an object slow down from its current velocity to 0 in a certain distance. In a for loop there would be the current speed, then the goal (0), then the change which is removed from the current speed. I need to calculate the change so it slows down and is at 0 when at the ending position.
this is what I tried:
local n = currentV / (object.Core.Position-script.Parent.EndPosition.Position).magnitude for i=currentV, 0, n do n = currentV / (object.Core.Position-script.Parent.EndPosition.Position).magnitude object.Core.BodyVelocity.Velocity = object.Core.CFrame.lookVector * i wait() end
I set 'n' as the difference. I need help on how to calculate 'n'. Cheers
Try this
local n = (object.Core.Position - script.Parent.EndPosition.Position).magnitude if n <= VALUE then for i = VALUE2, 0, -RATE do object.Core.BodyVelocity.Velocity = object.Core.BodyVelocity.Velocity - i wait() end end
If it doesn't work, try removing BodyVelocity and use the part's velocity instead:
object.Core.Velocity
Basically, If the current velocity reaches a magnitude/distance of VALUE, it will run the loop. For doing a for loop, you would want a start value, end value, and rate of change. Since you want to change object.Core's velocity, you would take the object's velocity it is at and subtract it by a rate of however you like it, until it reaches 0 velocity.