How would I set the Maximum Velocity of a Prop.

Let’s say I have this prop, and I want to launch it, move it, drop it and even more. How would I go about setting a maximum velocity ( a max movement speed of the prop ) in chosen directions or all directions?

Reduced Exemple: I want my prop to go max 5 km/h.

[lua]function LimitVelocity(ent,vel)
hook.Add(“Think”,ent:EntIndex()…“LimitVelocity”,function()
if ent:GetVelocity():Length() > vel then ent:SetVelocity(ent:GetVelocity():Normalize()*vel) end
end)
end[/lua]

Something like this perhaps?

I like how people rate dumb, but can’t suggest anything better.

Where is vel coming from? You are having vel being passed from nowhere from the Think hook, that doesn’t exactly work now does it?

Say you wanted 500 as the cap.
[lua]
local vel = 500
function LimitVelocity(ent)
hook.Add(“Think”,ent:EntIndex()…“LimitVelocity”,function()
if ent:GetVelocity():Length() > vel then ent:SetVelocity(ent:GetVelocity():Normalize()*vel) end
end)
end[/lua]
Or better yet, just have the number in there in the first place, instead of wasting variable space.
[lua]
function LimitVelocity(ent)
hook.Add(“Think”,ent:EntIndex()…“LimitVelocity”,function()
if ent:GetVelocity():Length() > 500 then ent:SetVelocity(ent:GetVelocity():Normalize()*500) end
end)
end[/lua]
Unless of course you want the velocity to be changeable, then you would store it in the ent’s table:
[lua]
–Somewhere in the ent spawn code:
ent.maxvel = 500 – Set a variable tied to the ent for the maximum velocity

function LimitVelocity(ent)
hook.Add(“Think”,ent:EntIndex()…“LimitVelocity”,function()
if ent:GetVelocity():Length() > ent.maxvel then ent:SetVelocity(ent:GetVelocity():Normalize()*ent.maxvel) end
end)
end[/lua]

Use Damping.

It would probably take some estimation to figure out how the damping is related to the speed ( I don’t know ), but this is a much more efficient solution than a think hook for each entity.

‘vel’ is still in scope.