I'm in need of a method of making an entity move to a set of coordinates at a set speed. I've tried using ApplyForceCenter, but I can't seem to find a reliable way to move it. The speed will variate depending on the distance, and some objects will attempt to roll.
I think this should be enough to describe what I need, but I'll include some other stuff in case it'll be of help.
The entity should be able to be any kind of model, and there's only need for rotation around yaw(? left and right, not up and down or doing a roll). I've tried using constraint.Keepupright, but I can't get this to work.
I've got no need for the speed to scale (f.ex. a smooth start, or slow end).
edit:
My main problem with applyforcecenter is that I found no clean way to set the speed, and there was really unnecessary ground friction. Something like the Hammer movelinear (I think it was) would be quite ideal. I need no collision, though it'd be nice if one could reduce the speed for a while, and then set the speed up again.
Disable gravity on the physics object, set it's position to x units above the ground then set it's velocity instead of applying force. Have a timer to check when it's near it's destination and stop it or simply lerp it from one point to the other, from the sound of things you should probably lerp it.
and now for some untested written in browser code:
function lerpObject(obj, objDest, objStart, timeToDest, lerpStartTime)
if obj and ValidEntity(obj) then
if !objDest then return end
if !objStart then objStart = obj:GetPos() + Vector(0,0,10) end
if !timeToDest then timeToDest = 2 end
if !lerpStartTime then lerpStartTime = CurTime() end
local lerpDelta = CurTime() - lerpStartTime
lerpPerc = math.Clamp(lerpDelta / timeToDest, 0, 1)
local objPhys = obj:GetPhysicsObject()
if objPhys and objPhys:IsValid() then
if lerpPerc < 1 then
objPhys:EnableGravity(false)
else
objPhys:EnableGravity(true)
end
end
obj:SetPos(LerpVector(lerpPerc, objStart, objDest))
if lerpPerc < 1 then
timer.Simple(0.1, lerpObject, obj, objDest, objStart, timeToDest, lerpStartTime)
end
end
end
the idea is that because it loops with a timer you run this on multiple things at a time and each will finish after x time, usage:
lerpObject(myProp, Vector(234,1234,3432), , 2) -- that should move the myProp ent to vector(234,1234, 3432) over 2 seconds time
hope that works and hope that helps, i'll test/ clean it later if it doesn't work and repost it.
Edited:
So just realized that's gonna be jerky only running once every tenth of a second, you can play with the setting till it looks good or you can even add some velocity to the object so it will reach the next point on it's own before the next iteration of the function runs.