garrysmod-issues
garrysmod-issues copied to clipboard
entity:SetVelocity()
Hello I noticed that when we setVelocity an entity we can not reset it. Indeed, my print(ent:GetVelocity()) output -1227 in x while I SetVelocity to 0 just before
function dropoffFlight(ent, dropPos)
if not IsValid(ent) then return end -- Prevent if 'ent' is not valid
local dropVehicle = ents.Create("lunasflightschool_atte")
if not IsValid(dropVehicle) then return end -- Prevent if 'dropVehicle' is not valid
local inFlight = true
local dropped = false
local timerName = "inFlightTimer" .. math.random(0, 1000)
local moveVector = Vector(-10, 0, 0)
local stopVector = Vector(0, 0, 0)
originalAngle = dropVehicle:GetAngles()
print(dropPos)
timer.Create(timerName, FrameTime(), 0, function()
if not IsValid(ent) then
timer.Remove(timerName)
return
end
if inFlight then
--print( ent:GetPos():DistToSqr(dropPos) )
if ent:GetPos():DistToSqr(dropPos) < 10000000 then
inFlight = false
dropped = true
print("test")
ent:SetMoveType(MOVETYPE_NONE)
ent:SetVelocity(stopVector)
--ent:SetMoveType(MOVETYPE_FLY)
print(ent:GetVelocity())
timer.Remove(timerName)
timer.Simple(5, function()
if IsValid(ent) then removeEntity(ent) end
end)
end
if not dropped then
--print("test1")
ent:SetVelocity(moveVector)
end
end
end)
end
Have you tried SetVelocityInstantaneous?
yes
try ent:GetPhysicsObject():SetVelocity() and SetAngleVelocity too
i have already try this but not working i have conclude that when can reset an entity velocity, it’s very strange i have ask on some big discord communautary and nobody understands why it’s not working
hi buddy! i think i may of found a fix for you lmk if its works!
ent:SetVelocity(stopVector)
change this line to these three lines, because setting a velocity of 0 apparently just adds 0 to the velocity, causing no change
local stopVector = ent:GetVelocity()
stopVector:Negate()
ent:SetVelocity(stopVector)
(also delete your declaration for stopVector at the top of your code)
okk thx i will try this
Quote from Entity:SetVelocity - Garry's Mod Wiki
WARNING If applied to a player, this will actually ADD velocity, not set it.
I guess this might be related.