Gorilla.PhysicsCharacterController
Unit Gorilla.PhysicsCharacterController.pasClasses
- TGorillaPhysicsCharacterController = class ( TDummy )
Records
- record TRayCastReturn
Constants
- const OUT_OF_RANGE : Integer = $2710;
Mics. types
- type PRayCastReturn = pointer to TRayCastReturn;
TRayCastReturn
Fields
- public Dir :
TPoint3D
- public DirCount :
Integer
- public Hit :
Boolean
- public HitPos :
TPoint3D
- public Slop :
Single
- public NextPos :
TPoint3D
- public NextDist :
Single
- public SourceBody :
TQ3Body
- public CastedBody :
TQ3Body
- public CastedCtrl :
TControl3D
- public StaticCollision :
Boolean
- public DynamicCollision :
Boolean
Methods
TGorillaPhysicsCharacterController
The physics character controller component is a helper component to link physics, character controller and a 3D model together. The component handles movement and viewport updates in an optimized way.
Ancestors
Members
Fields
- protected FModel :
TGorillaModel
- protected FAnimationController :
TGorillaAnimationController
- protected FController :
TGorillaCharacterController
- protected FPhysics :
TGorillaPhysicsSystem
- protected FUseRayCasting :
Boolean
- protected FModified :
Boolean
- protected FUnlocked :
Boolean
- protected FUpdateTime :
Single
- protected FGravityScale :
Single
- protected FSlop :
Single
- protected FRayDirection :
TPoint3D
- protected FRayOffset :
Single
- protected FCapsulePrefab :
TGorillaColliderSettings
- protected FOnUpdate :
TNotifyEvent
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- protected function GetGorillaViewport ( ) : TGorillaViewport ;
- protected function GetController ( ) : TGorillaCharacterController ;
- protected procedure SetController ( const AValue : TGorillaCharacterController ) ;
- protected function GetModel ( ) : TGorillaModel ;
- protected procedure SetModel ( const AValue : TGorillaModel ) ;
- protected function GetAnimationController ( ) : TGorillaAnimationController ;
- protected procedure SetAnimationController ( const AValue : TGorillaAnimationController ) ;
- protected function GetPhysics ( ) : TGorillaPhysicsSystem ;
- protected procedure SetPhysics ( const AValue : TGorillaPhysicsSystem ) ;
- protected procedure SetGravityScale ( const AValue : Single ) ;
- protected procedure SetUseRayCasting ( const AValue : Boolean ) ;
- protected procedure SetSlop ( const AValue : Single ) ;
- protected procedure Resize3D ( ) ; override;
- protected procedure VerifyMoveDir
(
var
ADir :
TPoint3D
)
;
Takes an input direction vector and checks for blocked axis settings to prevent from illegal movement. The method will manipulate the variable parameter.
- protected procedure DoUpdateCapsulePrefab
(
)
;
Updates the physics capsule collider setting, this will not be published here to the physics system! Publishing is done by DoSetupCapsuleCollider().
- protected procedure DoSetupCapsuleCollider
(
)
;
Registers the capsule collider for physics controller in physics system. Any previously registered collider will be removed.
- protected procedure DoApplyCharacterController
(
)
;
Connects a linked character controller with the physics controller.
- protected procedure DoDispatchCharacterState
(
const
AHotKey :
TGorillaCharacterControllerHotKey; const
AStates :
TGorillaCharacterControllerStates
)
;
Dispatches input hotkeys and states to a linked animation controller for automatic animation playback.
- protected procedure DoPerformSynchronizedRayCastUpdate ( ) ;
- protected procedure DoOnQ3BodySleep
(
ASender :
TObject
)
;
Callback when the capsule collider was set to sleep by the physics system. The method will start idle mode. DoOnIdle() will finally set the collider to sleep.
- protected procedure DoOnQ3BodyWakeup ( ASender : TObject ) ;
- protected procedure DoOnQ3BodyUpdate ( ASender : TObject; const ACollider : TQ3Collider ) ;
- protected procedure DoOnHotKey
(
ASender :
TObject; const
AKind :
TGorillaCharacterControllerHotKey; const
AHotKey :
TGorillaHotKeyItem; const
AStates :
TGorillaCharacterControllerStates; const
AMode :
TGorillaInputMode
)
;
Internal callback method to dispatch hotkey settings to the DoDispatchCharacterState() method to automatically playback animations.
- protected procedure DoOnIdle
(
ASender :
TObject; AState :
TGorillaCharacterControllerState; AMode :
TGorillaInputMode
)
;
Internal callback method to handle state changes to idle-mode. The method will potentially set the physics collider to sleep, to stop movement immediately.
- protected procedure DoOnRotate
(
ASender :
TObject; ACurrentRotation :
TQuaternion3D; ANewRotation :
TQuaternion3D; ADelta :
TPointF
)
;
Rotates the character / avatar model by submitted parameters.
- protected procedure DoOnMove
(
ASender :
TObject; AKind :
TGorillaCharacterControllerHotKey; ADir :
TPoint3D; ACurrentSpeed :
Single
)
;
Internal callback method for user specific movements. The mehtod will move the capsule collider in 3D space and by that automatically move the character.
- protected procedure DoOnChangeSize
(
ASender :
TObject
)
;
Internal callback method is getting called, when character state changes from / to crawling/crouching. Then the collider size need to change too.
- protected procedure DoOnMoveByRayCast
(
ASender :
TObject; AKind :
TGorillaCharacterControllerHotKey; ADir :
TPoint3D; ACurrentSpeed :
Single; var
AForced :
Boolean
)
;
Subroutine to be called by DoOnMove. Moves the physics character controller by raycasting all registered physics bodies. This method expects a static collider and do not interact with other colliders directly.
- protected procedure DoOnMoveByColliders
(
ASender :
TObject; AKind :
TGorillaCharacterControllerHotKey; ADir :
TPoint3D; ACurrentSpeed :
Single; var
AForced :
Boolean
)
;
Subroutine to be called by DoOnMove. Moves the physics character controller by impulse control inside physics engine. This may lead to sliding characters but interacts directly as dynamic collider will all other colliders.
- protected procedure Render
(
)
;
override;
We overwrite the render method to update physics if FModified was changed to TRUE. Due to designtime mode we need an independent update way.
- protected procedure Notification ( AComponent : TComponent; Operation : TOperation ) ; override;
- public procedure AfterConstruction ( ) ; override;
Properties
- public GorillaViewport : TGorillaViewport
Returns the viewport of the physics character controller as destiny for update processes.
read GetGorillaViewport - published Model : TGorillaModel
- published AnimationController : TGorillaAnimationController
An animation controller working with a linked model. Input messages will be pushed to animation controller for automatic animation switching/transitions.
read GetAnimationController
write SetAnimationController - published Controller : TGorillaCharacterController
A linked TGorillaFirstPersonController or TGorillaThirdPersonController will handle character movement and physics collision detection.
read GetController
write SetController - published Physics : TGorillaPhysicsSystem
A linked physics system in which a capsule collider will be added for collision detection. The capsule collider will be controlled by the linked character controller.
read GetPhysics
write SetPhysics - published UseRayCasting : Boolean
(De)Activates movement by raycasting or by physics colliders.
read FUseRayCasting
write SetUseRayCasting - published Slop : Single
- published RayDirection : TPoint3D
The RayDirection defines in which direction the controller will be adjusted. Default direction is (0, 1, 0), which means downwards.
read FRayDirection
write FRayDirection - published RayOffset : Single
Get or set ray offset from where the raycasting is started. The offset will be computed from current physics character controller position.
read FRayOffset
write FRayOffset - published UpdateTime : Single
Because physics, animation and movement control is very complex and time critical, you can configure the minimum update time limit for animations by the UpdateTime value. The default value is 0.02 (in seconds) = 20ms.
read FUpdateTime
write FUpdateTime - published GravityScale : Single
Get or set speed to influence character movement by capsule collider.
read FGravityScale
write SetGravityScale