Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to calculate the difference in which an object needs to slow down in a certain distance?

Asked by
Quirtx 0
5 years ago
Edited 5 years ago

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

1 answer

Log in to vote
0
Answered by
iTamago 18
5 years ago
Edited 5 years ago

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.

Ad

Answer this question