Hello, so, what i'm trying to do is make a tool that will make props float and by float I mean maintain a certain distance from the ground and keep the angles it had when it was shot with the tool. So far it does most of what I want it to, except.... the angles, I could just set the angles, but I want it to wobble a little or even tip if you stand near the edge so i'm using PhysObj:AddAngleVelocity() to compensate for any angle discrepancies from the original angles.
Which brings me to the problem, for the life of me I can't make it fix the angles, I think i'm close because when I spawn it it doesn't spazz right away, it does exactly what it's supposed to, then after walking on it and disrupting the balance, it slowly goes ape shit on me.
so here's the think hook i'm using to manage this feat.
The codes a mess at the moment, I've tried so many things.
But to recap floating off the ground isn't the problem, also I'm using SysTime for accuracy, the delta is usually 0.01 to 0.03 depending on the number of props I use the tool on.
[lua]
local function floatThink()
local floatThinkDelta = SysTime() - floatThinkTime
for k, prop in pairs(floatingProps) do
if ValidEntity(prop) then
local floatTraceData = {}
floatTraceData.start = prop:GetPos()
floatTraceData.endpos = prop:GetPos() + (GetWorldEntity():GetUp() * -16668)
floatTraceData.filter = prop
local floatTrace = util.TraceLine(floatTraceData)
local propDist = floatTrace.HitPos:Distance(prop:GetPos())
local pPhys = prop:GetPhysicsObject()
if !(pPhys == nil) and (pPhys:IsValid()) then
local newVel = ((GetWorldEntity():GetUp() * (prop.floatHeight - propDist)) * (pPhys:GetVolume() / pPhys:GetMass())) * floatThinkDelta
local angVel = angDiff( prop:GetAngles(), prop.goalAngle)
local angVel2 = angDiff( prop.goalAngle, prop:GetAngles())
local angO = angVel - angVel2
local finalVel = Angle(0,0,0)
if angVel.p < -1 then
finalVel.p = angVel.p * floatThinkDelta
elseif angVel.p > -1 then
finalVel.p = angVel2.p * floatThinkDelta
else
finalVel.p = 0
end
if angVel.y < -1 then
finalVel.y = angVel.y * floatThinkDelta
elseif angVel.y > -1 then
finalVel.y = angVel2.y * floatThinkDelta
else
finalVel.y = 0
end
if angVel.r < -1 then
finalVel.r = angVel.r * floatThinkDelta
elseif angVel.r > -1 then
finalVel.r = angVel2.r * floatThinkDelta
else
finalVel.r = 0
end
print("loc curAngle: " .. tostring(prop:GetLocalAngles()))
print("goalAngle: " .. tostring(prop.goalAngle))
print("curAngle: " .. tostring(prop:GetAngles()))
print("angO: " .. tostring(angO))
print("newVel: " .. tostring(newVel))
print("angVel: " .. tostring(angVel))
print("angDiff: " .. tostring(angDiff( prop:GetAngles(), prop.goalAngle)))
print("angVel2: " .. tostring(angVel2))
print("angDiff2: " .. tostring(angDiff( prop.goalAngle, prop:GetAngles())))
print("floatThinkDelta: " .. tostring(floatThinkDelta))
pPhys:SetVelocity(newVel)
pPhys:AddAngleVelocity((pPhys:GetAngleVelocity() * -1) + (finalVel * 10))
--pPhys:AddAngleVelocity(finalVel )
end
print("floating prop " .. tostring(prop))
else
table.remove(floatingProps, k)
end
end
floatThinkTime = SysTime()
end
hook.Add("Think", "propFloatThink", floatThink)
[/lua]
Some of the variables are garbage like angO, and I made them just to see what different values look like.
I'm not removing them right now in case one of them is needed, I will clean it all up when I get it working.
Thanks in advance for any help.
Sorry, you need to Log In to post a reply to this thread.