A way to detect when to objects collide?

two*
I’ve been trying to figure this out for ages now, and had to stop working on my gamemode because I couldn’t find a way to do it. Is there a hook or some other method I can use to detect collisions between two objects, namely two vehicles? I also need it to report what the two entities were that collided.

**[ENT.Touch

http://wiki.garrysmod.com/favicon.ico](http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexcdb2.html?title=ENT.Touch)**

Look at the code of the sent_ball (Bouncy Ball).

But I can’t use SENT hooks to detect collisions between things that aren’t SENTs can I?

I would also love to know this, I don’t think there is a descent way tho. There’s that ShouldCollide hook, but its not reliable.

ShouldCollide doesn’t work like that, I’ve tried it. It’s called every tick basically, not right before things are colliding.

Entity.PhysicsCollide.

You can use it on entities that you didn’t make by overriding their PhysicsCollide method.

[lua]-- myEnt is my entity.
local oldPhysicsCollide = myEnt.PhysicsCollide
function myEnt:PhysicsCollide(data, physobj)
– Do shiz.
oldPhysicsCollide(self, data, physobj)
end
[/lua]

I told you to look a the bouncy ball’s code:

[lua]
–[[---------------------------------------------------------
Name: PhysicsCollide
-----------------------------------------------------------]]
function ENT:PhysicsCollide( data, physobj )

-- Play sound on bounce
if (data.Speed > 80 && data.DeltaTime > 0.2 ) then
	self:EmitSound( "Rubber.BulletImpact" )
end

-- Bounce like a crazy bitch
local LastSpeed = math.max( data.OurOldVelocity:Length(), data.Speed )
local NewVelocity = physobj:GetVelocity()
NewVelocity:Normalize()

LastSpeed = math.max( NewVelocity:Length(), LastSpeed )

local TargetVelocity = NewVelocity * LastSpeed * 0.9

physobj:SetVelocity( TargetVelocity )

end
[/lua]

Yeah I knew about that function but I was confused about the difference between a SENT in gmod and a regular entity. So you are saying that I can use this function with any entity even if it is not Lua based, like a jeep or a regular prop for example?

I don’t actually think you can, so what I was going to do was make an invisible SENT with a bounding box the size of the jeep’s which would then have a PhysicsCollide hook in it. The other method I was considering was combining Entity.GetCollisionBounds with ents.FindInBox, but I don’t know if that will work at all.

I actually asked this exact same question awhile back with no luck:
http://www.facepunch.com/threads/1059660

Yeah I found that thread while searching for an answer. Do you know if FindInBox will find entities that are partially in the box, like if I had a jeep whose front was like 5 inches inside the box would it be counted?

I’ve asked this question before as well, like 2 years ago, nobody knew the answer then either. I wish there were more people that browsed this forum looking to answer questions rather than ask them.