Class TRigidBody

Unit

Declaration

type TRigidBody = class(TComponent)

Description

Rigid body properties for the physics engine, see TCastleTransform.RigidBody.

TODO: For now all the properties of this class, including the Collider and all properties of Collider, must be assigned before setting TCastleTransform.RigidBody .

Hierarchy

  • TComponent
  • TRigidBody

Overview

Methods

Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Setup2D;
Public procedure InitializeTransform(const Transform: TCastleTransform);
Public procedure DeinitializeTransform(const Transform: TCastleTransform);
Public procedure Update(const Transform: TCastleTransform; const SecondsPassed: Single);
Public function GetCollidingTransforms: TCastleTransformList;

Properties

Public property AngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity;
Public property AngularVelocityDamp: Single read FAngularVelocityDamp write SetAngularVelocityDamp;
Public property MaximalAngularVelocity: Single read FMaximalAngularVelocity write SetMaximalAngularVelocity;
Public property LinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity;
Public property LinearVelocityDamp: Single read FLinearVelocityDamp write SetLinearVelocityDamp;
Public property MaximalLinearVelocity: Single read FMaximalLinearVelocity write SetMaximalLinearVelocity;
Public property InitialAngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity; deprecated 'use AngularVelocity';
Public property InitialLinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity; deprecated 'use LinearVelocity';
Public property OnCollisionEnter: TOnCollision read FOnCollisionEnter write SetOnCollisionEnter;
Public property OnCollisionExit: TOnCollision read FOnCollisionExit write SetOnCollisionExit;
Public property OnCollisionStay: TOnCollision read FOnCollisionStay write SetOnCollisionStay;
Published property Dynamic: Boolean read FDynamic write FDynamic default true;
Published property Animated: Boolean read FAnimated write FAnimated default false;
Published property Trigger: Boolean read FTrigger write SetTrigger default false;
Published property Collider: TCollider read FCollider;
Published property Gravity: Boolean read FGravity write FGravity default true;
Published property LockTranslation: T3DCoords read FLockTranslation write FLockTranslation;
Published property LockRotation: T3DCoords read FLockRotation write FLockRotation;
Published property Exists: Boolean read FExists write SetExists default true;

Description

Methods

Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure Setup2D;

Utility function to set common values for physics in 2D games. Locks moving along the Z axis, locks rotating along the X and Y axes.

Public procedure InitializeTransform(const Transform: TCastleTransform);

Connect this rigid body with Transform and Transform.World.

Public procedure DeinitializeTransform(const Transform: TCastleTransform);

Disconnect from Transform.World, if was connected.

Public procedure Update(const Transform: TCastleTransform; const SecondsPassed: Single);
 
Public function GetCollidingTransforms: TCastleTransformList;

Transformations that we collide with currently.

Properties

Public property AngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity;
 
Public property AngularVelocityDamp: Single read FAngularVelocityDamp write SetAngularVelocityDamp;
 
Public property MaximalAngularVelocity: Single read FMaximalAngularVelocity write SetMaximalAngularVelocity;
 
Public property LinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity;
 
Public property LinearVelocityDamp: Single read FLinearVelocityDamp write SetLinearVelocityDamp;
 
Public property MaximalLinearVelocity: Single read FMaximalLinearVelocity write SetMaximalLinearVelocity;
 
Public property InitialAngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity; deprecated 'use AngularVelocity';

Warning: this symbol is deprecated: use AngularVelocity

 
Public property InitialLinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity; deprecated 'use LinearVelocity';

Warning: this symbol is deprecated: use LinearVelocity

 
Public property OnCollisionEnter: TOnCollision read FOnCollisionEnter write SetOnCollisionEnter;

Occurs when TRigidBody starts colliding with another TRigidBody.

It can occur repeatedly for the same body (in the same time instant) if the collision has many points of contact.

Warning: Do not free the TCastleTransform instances that collide during this event. It would free the rigid body instance, which will crash the physics engine for now. Instead, you can set TCastleTransform.Exists to False (you can free it later, e.g. during TInputListener.OnUpdate).

Public property OnCollisionExit: TOnCollision read FOnCollisionExit write SetOnCollisionExit;

Occurs when TRigidBody stops colliding with another TRigidBody.

Warning: Do not free the TCastleTransform instances that collide during this event. It would free the rigid body instance, which will crash the physics engine for now. Instead, you can set TCastleTransform.Exists to False (you can free it later, e.g. during TInputListener.OnUpdate).

Public property OnCollisionStay: TOnCollision read FOnCollisionStay write SetOnCollisionStay;

Occurs when TRigidBody still collides with another TRigidBody.

Warning: Do not free the TCastleTransform instances that collide during this event. It would free the rigid body instance, which will crash the physics engine for now. Instead, you can set TCastleTransform.Exists to False (you can free it later, e.g. during TInputListener.OnUpdate).

Published property Dynamic: Boolean read FDynamic write FDynamic default true;

Does the physics simulation move and rotate this object (because of gravity, or because it collides with others).

true (dynamic object, the default)

In this case you cannot change the TCastleTransform.Translation and other transformation properties of the related TCastleTransform after assigning TCastleTransform.RigidBody. They are under the control of the physics engine. You can still reliably read them.

Also, the value Animated is ignored in this case.

false

In this case object is not transformed by the physics simulation. It still collides with other physical objects.

You can change the TCastleTransform.Translation and other transformation properties by your own code. But if you plan to change them very often (e.g. every frame), then set the Animated property to True.

Published property Animated: Boolean read FAnimated write FAnimated default false;

Is the transformation of this object updated often (relevant only when Dynamic = False).

This property is taken into account only if Dynamic = False. When Dynamic = False, you can change the TCastleTransform.Translation and other transformation properties of the related TCastleTransform. This property is an optimization hint to the physics engine, it says how often you will change the transformation.

true (animated object, also known as "kinematic")

The physics engine is prepared that this object can move often, e.g. every frame, so you can animate the related TCastleTransform using any technique.

false (static object)

Changing the transformation properties is costly, it may even be like destroying this object and creating a new one from the point of view of the physics engine, so do not change them often, e.g. every frame.

The upside is that collisions with static objects may be much more optimized, since the physics engine can assume that all the static objects form a completely frozen unmovable geometry in the world.

Published property Trigger: Boolean read FTrigger write SetTrigger default false;

Triggers report when other object collides with them, but still allow the other object to pass through. In other words, colliding with a trigger will not cause the collider to stop or "bounce off" the trigger.

They are useful as sensors. E.g. a trigger may be a coin (like in "Mario") that the player can "consume" by colliding with it.

Triggers report collisions through the same events as other rigid bodies: (TRigidBody.OnCollisionEnter, TRigidBody.OnCollisionStay, TRigidBody.OnCollisionExit).

Published property Collider: TCollider read FCollider;

Shape used for collisions with this object. You cannot assign this property directly, it is automatically assigned when you create a TCollider specifying this TRigidBody as it's parent.

Published property Gravity: Boolean read FGravity write FGravity default true;

Is this object affected by gravity.

Published property LockTranslation: T3DCoords read FLockTranslation write FLockTranslation;

Disable motion (TCastleTransform.Translation change) along the particular (world) axis.

For 2D games, you will usually want to disable motion along the Z axis. Instead of directly changing this property, you can achieve this by calling Setup2D.

Published property LockRotation: T3DCoords read FLockRotation write FLockRotation;

Disable rotation (TCastleTransform.Rotation change) along the particular (world) axis.

For 2D games, you will usually want to disable rotation along the X and Y axes. Instead of directly changing this property, you can achieve this by calling Setup2D.

Published property Exists: Boolean read FExists write SetExists default true;

Controls whether the rigid body is actually processed by the physics engine. When this is False, the rigid body is not updated by the physics engine, and it does not cause collisions with other rigid bodies.


Generated by PasDoc 0.15.0.