Need help using BoundingRadius to calculate distance
1 replies, posted
I'm trying to make it so you get 'thrown out' of a prop if you're stuck in it awhile after you drop it with your physgun. The prop is made pass-through-able when you drop it until a certain point in time where it throws out any players stuck in it.
Here's the code for it so far:
shared.lua:
[lua]local function PhysgunProtection(ply, ent)
if ent:IsWeapon() == false then
ent:SetCollisionGroup(2)
ent:DrawShadow(false)
ent:SetCustomCollisionCheck(true)
timer.Create( "MakePropNormal", 4 , 1, function()
propphysmarked = ent
timer.Create("MakePropNormal2", 0.1, 1, function()
if ent == propphysmarked then
propphysmarked.MakeNoCollided = 1
ent:SetCollisionGroup(0)
timer.Create("MakePropNormal2.1", 0.1, 1 , function()
ent:SetCollisionGroup(2)
timer.Create("MakePropNormal2.3", 1, 1 , function()
ent:SetCollisionGroup(0)
propphysmarked.MakeNoCollided = 0
ent:DrawShadow(true)
end )
end )
end
end )
end )
end
end
local function PropRepulsion( ent1, ent2)
if ent1:IsWorld() != true then
if ent2:IsWorld() != true then
if ent1 == propphysmarked then
if ent1.MakeNoCollided == 1 then
velocitymoderator = 0
if ent1:BoundingRadius() > 100 then
velocitymoderator = 50
end
if ent1:BoundingRadius() > 300 then
velocitymoderator = 50
end
if ent1:BoundingRadius() > 500 then
velocitymoderator = 400
end
if ent1:BoundingRadius() > 700 then
velocitymoderator = 450
end
if ent1:BoundingRadius() > 900 then
velocitymoderator = 500
end
if ent1:BoundingRadius() > 1100 then
velocitymoderator = 550
end
if ent1:BoundingRadius() > 1300 then
velocitymoderator = 600
end
if ent1:BoundingRadius() > 1500 then
velocitymoderator = 970
end
if ent1:BoundingRadius() > 1700 then
velocitymoderator = 1170
end
if ent1:BoundingRadius() > 1900 then
velocitymoderator = 1370
end
if ent1:BoundingRadius() > 2100 then
velocitymoderator = 1570
end
if ent1:BoundingRadius() > 2300 then
velocitymoderator = 1770
end
if ent1:BoundingRadius() > 2500 then
velocitymoderator = 1950
end
print(ent1:BoundingRadius())
print(velocitymoderator)
ent2:SetVelocity(Vector(ent1:BoundingRadius()+20-velocitymoderator,ent1:BoundingRadius()+20-velocitymoderator,ent1:BoundingRadius()+20-velocitymoderator))
end
end
elseif ent2 == propphysmarked then
if ent2.MakeNoCollided == 1 then
velocitymoderator = 0
if ent2:BoundingRadius() > 100 then
velocitymoderator = 50
end
if ent2:BoundingRadius() > 300 then
velocitymoderator = 50
end
print(ent2:BoundingRadius())
print(velocitymoderator)
ent1:SetVelocity(Vector(ent2:BoundingRadius()+20-velocitymoderator,ent2:BoundingRadius()+20-velocitymoderator,ent2:BoundingRadius()+20-velocitymoderator))
end
end
end
end
hook.Add("ShouldCollide","Player/Prop Protection and Repulsion", PropRepulsion)
hook.Add( "PhysgunDrop", "Physgun Item Ghosting", PhysgunProtection)[/lua]
My problem is that I have no way of averaging out the force of which the players are thrown. Depending on the prop they can either continue to be stuck, just squeeze out, or be thrown half-way across the map. I tried to use a variable called 'velocity moderator' that changes based on the BoundingRadius of the prop, but I'm unable to work out a way to make it so you get pushed just enough for every prop to get out without being thrown half-way across the map.
Any help with this would be appreciated
Bumping this because I got no reply
Sorry, you need to Log In to post a reply to this thread.