Discord
Steam
/
Developers
/
Can't GetPhysi..
Login/Join
Event Log
Can't GetPhysicsObject of a prop
3 replies, posted
Search
In This Thread
print("PLAYER") print("------") pos = LocalPlayer():GetPos() aim = LocalPlayer():GetAimVector() print(pos) print("------") print("PHYSICS PROPS") print("-------------") pprops = ents.FindByClass("prop_physics") for i, item in pairs(pprops) do print(i.." : "..pos:Distance(item:GetPos())) end print("-------------") print("SORTED PROPS") print("------------") table.sort(pprops, function(a, b) return pos:Distance(a:GetPos()) < pos:Distance(b:GetPos()) end) for i, item in pairs(pprops) do print(i.." : "..pos:Distance(item:GetPos())) end print("------------") print("FILTERED PROPS") print("--------------") filtered = {} for i, item in pairs(pprops) do if pos:Distance(item:GetPos()) <= 350 then table.Add(filtered, {item}) end end for i, item in pairs(filtered) do print(i.." : "..pos:Distance(item:GetPos())) end print("--------------") print('PUSHING PROPS') print('-------------') for i, item in pairs(filtered) do print(item) print('pushing '..i) print('------- '..i) local phys = item:GetPhysicsObject() --if (!IsValid(phys)) then -- print('error '..i) --else local velocity = aim * 100 + (VectorRand() * 10) phys:ApplyForceCenter(velocity) print('pushed '..i) --end print('------- '..i) end print('-------------') Before lines at the end of the file commented the output was: PLAYER ------ 280.351471 5289.250000 -13823.968750 ------ PHYSICS PROPS ------------- 1 : 17998.36773262 2 : 18002.492693997 3 : 17998.320378437 4 : 18002.445350665 5 : 17994.168930865 6 : 17998.284107941 . . . 91 : 17672.342712512 92 : 17581.32421506 93 : 17785.131985545 94 : 17563.891611127 95 : 186.43250373657 96 : 456.78880195687 97 : 127.21054081317 ------------- SORTED PROPS ------------ 1 : 127.21054081317 2 : 186.43250373657 3 : 456.78880195687 4 : 12606.671651713 5 : 12612.118351184 6 : 12648.67867878 . . . 95 : 18048.490460298 96 : 18055.180241734 97 : 18104.888582234 ------------ FILTERED PROPS -------------- 1 : 127.21054081317 2 : 186.43250373657 -------------- PUSHING PROPS ------------- Entity [73][prop_physics] pushing 1 ------- 1 error 1 ------- 1 Entity [72][prop_physics] pushing 2 ------- 2 error 2 ------- 2 ------------- And after: . . . PUSHING PROPS ------------- Entity [73][prop_physics] pushing 1 ------- 1 [ERROR] lua/testhw.lua:50: Tried to use a NULL physics object! 1. ApplyForceCenter - [C]:-1 2. unknown - lua/testhw.lua:50 Why i can't get physics object of physics prop?? P.S. Sorry for bad english ))
Physics objects don't exist clientside for props.
Thank you for answer. Do you know any solution?
Do whatever physics operations you need serverside.
Sorry, you need to
Log In
to post a reply to this thread.