• Collision Detection on Objects (not a SENT)
    2 replies, posted
I feel like this is probably one of those questions that pops up on a recurring basis... What I would like to do is make a "car tag" mini-game, where, upon the collision of two vehicles, the new vehicle is "tagged." Seems like it should be ridiculously simple; my only question is, what would be the best way to go about detecting the actual collision? From what I've researched, the ShouldCollide hook isn't very reliable and not intended to be used for this purpose, and the PhysicsCollide function only works inside of SENTs. Is a think hook and a distance check my best option, or is there a better way to check this?
[url]http://wiki.garrysmod.com/page/Entity/AddCallback[/url]
[QUOTE=Robotboy655;43867544][url]http://wiki.garrysmod.com/page/Entity/AddCallback[/url][/QUOTE] Thanks Robotboy, this is exactly what I was hoping for. One followup question though - Is there something special I need to set on the entity when spawning it, in order to be able to access the PhysObj data from that function? Several key table values (including HitEntity) don't show up when hitting anything (not even the world). Here is how I am spawning the vehicle: [code]local ent = ents.Create(vbase.Base) ent:SetPos(pos) ent:SetModel(vbase.Model) if ang then ent:SetAngles(ang) end ent:SetKeyValue( "vehiclescript", vbase.Script) ent:AddCallback( "PhysicsCollide", VehicleCollide ) ent:Spawn() ent:SetHealth(200) ent:Activate()[/code] And here is my callback function: [code]function VehicleCollide( ent, coldata, physobj ) print("Physics Collide called:",ent, coldata, physobj) PrintTable(coldata) end[/code] ent returns the entity as intended, and data returns the CollisionData table (missing HitEntity, PhysObject, TheirSpeed), and no PhysObject argument (col). I apologize if it is something obvious, the physics engine is [b]so[/b] not my realm.
Sorry, you need to Log In to post a reply to this thread.