Structures/CollisionData

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{Structure
 
{{Structure
| Description = Passed as argument of the {{HookFunction|ENTITY|PhysicsCollide}} event.
+
|Description=Passed as argument of {{HookFunction|ENTITY|PhysicsCollide}}.
| Fields =
+
 
{{StructureField|Vector|HitPos|The collisions position}}
+
{{Note|Sometimes, the value of 'Speed' can be different from getting the length calculated from 'OurOldVelocity', even though they should be the same, or close to same. It's recommended to do 'OurOldVelocity:Length()' instead.
{{StructureField|Entity|HitEntity|The other collision entities}}
+
<pre>
{{StructureField|Vector|OurOldVelocity|The entities velocity before the collision}}
+
ENT:PhysicsCollide( colData, collider )
{{StructureField|PhysObj|HitObject|The physics that collided}}
+
    -- you may get two completely different values, and the second one should be more accurate.
{{StructureField|number|DeltaTime|Time since the last collision}}
+
    print(colData.Speed)
{{StructureField|Vector|TheirOldVelocity|Speed of the other entity before the collision}}
+
    print(colData.OurOldVelocity:Length())
{{StructureField|number|Speed|The absolute speed of the entity before the collision}}
+
end
{{StructureField|Vector|HitNormal|Normal of the surface that hit the other entity}}
+
</pre> }}
 +
 
 +
|Fields={{StructureField|Vector|HitPos|The collision position}}{{StructureField|Entity|HitEntity|The other collision entity}}{{StructureField|Vector|OurOldVelocity|The entity's velocity before the collision}}{{StructureField|PhysObj|HitObject|Other entity's physics object}}{{StructureField|number|DeltaTime|Time since the last collision ''with this HitEntity''}}{{StructureField|Vector|TheirOldVelocity|Speed of the other entity before the collision}}{{StructureField|number|Speed|The speed of the entity before the collision}}{{StructureField|Vector|HitNormal|Normal of the surface that hit the other entity}}{{StructureField|PhysObj|PhysObject|Entity's physics object}}
 
}}
 
}}

Latest revision as of 17:03, 18 March 2018

Passed as argument of ENTITY:PhysicsCollide.
NOTE

Sometimes, the value of 'Speed' can be different from getting the length calculated from 'OurOldVelocity', even though they should be the same, or close to same. It's recommended to do 'OurOldVelocity:Length()' instead.

ENT:PhysicsCollide( colData, collider )
    -- you may get two completely different values, and the second one should be more accurate.
    print(colData.Speed)
    print(colData.OurOldVelocity:Length())
end



Type Name Description
Vector HitPos

The collision position

Entity HitEntity

The other collision entity

Vector OurOldVelocity

The entity's velocity before the collision

PhysObj HitObject

Other entity's physics object

number DeltaTime

Time since the last collision with this HitEntity

Vector TheirOldVelocity

Speed of the other entity before the collision

number Speed

The speed of the entity before the collision

Vector HitNormal

Normal of the surface that hit the other entity

PhysObj PhysObject

Entity's physics object

Personal tools
Navigation