Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
1.0.0:physics [2023/02/22 14:57] – created - external edit 127.0.0.1 | 1.0.0:physics [2023/03/16 09:00] – [Override Collider-Registration] admin | ||
---|---|---|---|
Line 95: | Line 95: | ||
^Type ^Description ^ | ^Type ^Description ^ | ||
- | |TQ3BodyType.eStaticBody | Static bodies have no Rigidbody | + | |TQ3BodyType.eStaticBody | Static bodies have no rigid body component attached to them, so the physics engine does not consider them to be moving. (Avoid moving these frequently or you'll violate that expectation). Use static colliders for level geometry like the ground and immovable walls, or stationary trigger volumes. Static colliders on their own won't set off trigger/ |
- | |TQ3BodyType.eDynamicBody|Dynamic bodies have a Rigidbody | + | |TQ3BodyType.eDynamicBody|Dynamic bodies have a rigid body component attached to them and their eKinematic flag is not set. These objects move at the whims of physics according to their linear/angular velocities and the forces/ |
- | |TQ3BodyType.eKinematicBody|Kinematic bodies have a Rigidbody | + | |TQ3BodyType.eKinematicBody|Kinematic bodies have a rigid body component with a set eKinematic flag. This tells the physics engine "this object moves, but I'll handle that part" — the kinematic object will process collisions with other rigid bodies, but only dynamic objects will automatically react by bouncing away, and cause messages to be sent. The kinematic object itself won't move except how you tell it to with MovePosition or MoveRotation — its velocity won't automatically integrate each timestep. Use this for objects that you want to control in ways that don't behave like simple physics bodies — like a bipedal character controller or highly custom vehicle controls. Use physics queries like overlap checks and shape casts to scan for collisions preemptively, |
===== Colliders ===== | ===== Colliders ===== | ||
Line 130: | Line 130: | ||
[[# | [[# | ||
- | Derived components of **TCustomMesh** and **TGorillaMesh** are supported for colliders. | + | Derived components of **TControl3D**, |
===== Threading ===== | ===== Threading ===== | ||
Line 213: | Line 213: | ||
* RemoteBodyImpulse | * RemoteBodyImpulse | ||
* RemoteBodyForce | * RemoteBodyForce | ||
+ | * RemoteBodyVelocity | ||
+ | * RemoteBodyAngularVelocity | ||
<file pascal> | <file pascal> | ||
Line 219: | Line 221: | ||
</ | </ | ||
- | By the methods above you're able to set a position and/or rotation explicitly, or to apply a force / impulse on a specific element. | + | By the methods above you're able to set a position and/or rotation explicitly, |
**__CAUTION: | **__CAUTION: | ||
+ | **__WARNING: | ||
===== Example ===== | ===== Example ===== | ||
+ | |||
+ | ==== Runtime Integration ==== | ||
+ | |||
For a working physics system you need a TGorillaPhysicsSystem component on your form. | For a working physics system you need a TGorillaPhysicsSystem component on your form. | ||
Line 293: | Line 299: | ||
end; | end; | ||
</ | </ | ||
+ | |||
+ | ==== Override Collider-Registration ==== | ||
+ | |||
+ | Default collider registration methods only support TControl3D objects. | ||
+ | But it is sometimes needed to register other types of objects for colliders, like a virtual instance of a mesh. | ||
+ | |||
+ | Writing a helper class gives you access to the protected internal registration methods which are unspecified by type: | ||
+ | ^Method ^ | ||
+ | |procedure DoAddBoxCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddSphereCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddCapsuleCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddTerrainCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |procedure DoAddMeshCollider(const AData : Pointer; const AType : PTypeInfo; const APrefab : TGorillaColliderSettings; | ||
+ | |||
+ | <file pascal> | ||
+ | type | ||
+ | /// < | ||
+ | /// Create a helper class to access protected methods for adding colliders. | ||
+ | /// Default methods only handle TControl3D instances, but we | ||
+ | /// want to add colliders dynamically for our virtual instances (TGorillaMeshInstance). | ||
+ | /// </ | ||
+ | TGorillaPhysicsHelper = class helper for TGorillaPhysicsSystem | ||
+ | public | ||
+ | procedure AddInstanceCollider(const ATemplate : TMeshDef; | ||
+ | const AData: TGorillaMeshInstance; | ||
+ | const AAbsoluteMatrix: | ||
+ | out ABody: TQ3Body); | ||
+ | end; | ||
+ | |||
+ | { TGorillaPhysicsHelper } | ||
+ | |||
+ | procedure TGorillaPhysicsHelper.AddInstanceCollider(const ATemplate : TMeshDef; | ||
+ | const AData: TGorillaMeshInstance; | ||
+ | const AAbsoluteMatrix: | ||
+ | out ABody: TQ3Body); | ||
+ | var LTransform : TMatrix3D; | ||
+ | begin | ||
+ | // Get the translation from absolute instance matrix | ||
+ | LTransform := TMatrix3D.CreateTranslation( | ||
+ | TTransformationMatrixUtils.GetTranslationFromTransformationMatrix(AAbsoluteMatrix) | ||
+ | ); | ||
+ | |||
+ | // Add a sphere collider for each instance with the maximum size of a side as radius | ||
+ | // or use another internal registration method, like DoAddBoxCollider, | ||
+ | DoAddSphereCollider(AData, | ||
+ | LTransform, Max(ASize.X, | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | When you have declared this kind of helper class in your unit, the TGorillaPhysicsSystem component will then show you a new method to be callable " | ||
Next step: [[fmodaudio|FMOD Audio]] | Next step: [[fmodaudio|FMOD Audio]] |