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

Acceleration Counter Script | One-Second Delay on player's Velocity.magnitude?

Asked by 6 years ago

I wanted to make an acceleration counter that shows the player's acceleration especially when falling or speeding up. I was thinking of having the player's Velocity.magnitude minus the Velocity.magnitude 1 SECOND AGO. This requires me to add a delay of 1 second on a while loop. Is there a way to delay the Velocity.magnitude reading by 1 second after the player moves?

math.randomseed(tick())
wait()

boop = game.Players.LocalPlayer
if boop.Character then
player = boop.Character
end


while true do           
    a = math.floor((((player.Head.Velocity.magnitude)-(--[[Velocity 1 second ago]])*2)*100))/100
    script.Parent.Text = a .. " studs/s^2"
    wait()
end 

1 answer

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago
Edited 6 years ago

Something like...

repeat wait() until game.Players.LocalPlayer.Character

game.Players.LocalPlayer.Character.Changed:connect(function()
    wait(1)
    a = math.floor((((player.Head.Velocity.magnitude)-(--[[Velocity 1 second ago]])*2)*100))/100
    script.Parent.Text = a .. " studs/s^2"
end)

...?

0
The script is what gives the value of the acceleration to the text which displays the acceleration. Basically I need a separate script that should take the Velocity.magnitude of the player 1 second ago. In other words, a 1 second delay of the Velocity.magnitude. Then in line 5, it's just the formula that subtracts the current Velocity.magnitude to the delayed Velocity.magnitude. Pulsarnova 0 — 6y
Ad

Answer this question