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

How to calculate the speed of a vehicle (seat)?

Asked by
Tesouro 407 Moderation Voter
10 years ago

If the VehicleSeat HeadsUpDisplay property is set to true, it shows a gui displaying the speed of the vehicle. How can I calculate that value, if it's a single number and the Velocity property of the seat is a Vector3?

3 answers

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
10 years ago

Ive tested this in studio. It might not be what you want. But this is what I found out and it works when I tested a car

local speed = 0

while (true) do
local p1 = script.Parent.Position
local t = wait()
local p2 = script.Parent.Position
local d = (p1-p2).magnitude
speed = math.floor(d/t)
print(speed) -- Showing the speed on the output
end
0
very intelligent, thx Tesouro 407 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Velocity is a Vector3 value, and every Vector value has a magnitude. The magnitude of a vector is basically how long the vector is, or the distance between itself and (0,0,0). In order to get the magnitude of a Vector, you simply type the name of the Vector and put .magnitude at the end of it to get the magnitude, like so:

local Speed = script.Parent.Velocity.magnitude

Hope this helped!

0
does it work? Tesouro 407 — 10y
0
Yes, this is what the VehicleSeat uses to display speed. Merely 2122 — 10y
Log in to vote
0
Answered by 10 years ago

this script goes inside the seat.

local sp = script.Parent

while wait() do local speed = math.floor(sp.Velocity.magnitude + .5)

print(speed)

end

Answer this question