Class TCastleRigidBody

Unit

Declaration

type TCastleRigidBody = class(TCastleBehavior)

Description

Use this behavior to be affected by physics collisions and forces. Add a TCastleRigidBody and some collider (TCastleCollider descendant) as behaviors of TCastleTransform to make the given TCastleTransform be affected by physics and collide with other physics bodies.

Source: transform/castletransform_physics.inc (line 691).

Hierarchy

Show Additional Members:

Overview

Methods

Protected function GetInternalText: String; virtual;
Protected procedure SetInternalText(const Value: String); virtual;
Protected procedure SetName(const Value: TComponentName); override;
Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual;
Public destructor Destroy; override;
Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual;
Public function PropertySections(const PropertyName: String): TPropertySections; virtual;
Public procedure SetTransient;
Public procedure AddNonVisualComponent(const NonVisualComponent: TComponent);
Public procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent);
Public procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent);
Public function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer;
Public function NonVisualComponentsCount: Integer;
Public function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator;
Public function ValueIsStreamed: Boolean; virtual;
Public procedure DesignerInfo(const SList: TStrings); virtual;
Public procedure DesignerWarnings(const SList: TStrings); virtual;
Protected procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual;
Protected procedure BeforeRender( const CameraView: TViewVectors; const ParentParentWorldTransformation: TTransformation); virtual;
Protected procedure ParentChanged; virtual; deprecated 'Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach';
Protected procedure ParentAfterAttach; virtual;
Protected procedure ParentBeforeDetach; virtual;
Protected procedure WorldAfterAttach; virtual;
Protected procedure WorldBeforeDetach; virtual;
Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; virtual;
Public procedure BeforeDestruction; override;
Public function World: TCastleAbstractRootTransform;
Protected procedure WorldAfterAttach; override;
Protected procedure WorldBeforeDetach; override;
Protected procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;
Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Setup2D;
Public function GetCollidingTransforms: TCastleTransformList;
Public function PhysicsRayCast(const RayOrigin, RayDirection: TVector3; const MaxDistance: Single = MaxSingle; const CollisionLayers: TPhysicsLayers = AllLayers): TRayCastResult;
Public function PhysicsSphereCast(const SphereOrigin: TVector3; const SphereRadius:Single; const SphereDirection: TVector3; const MaxDistance: Single = MaxSingle; const CollisionLayers: TPhysicsLayers = AllLayers): TRayCastResult;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public procedure AddForceAtPosition(const Force, Position: TVector3);
Public procedure AddForce(const Force: TVector3; const ForceInLocalCoordinates: Boolean);
Public procedure AddTorque(const Torque: TVector3);
Public procedure ApplyImpulse(const Impulse, Point: TVector3);
Public function ExistsInRoot: Boolean;
Public procedure WakeUp;
Public function Awake: Boolean;

Properties

Public property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents;
Public property IsLoading: Boolean read FIsLoading;
Public property Parent: TCastleTransform read FParent;
Public property ListenWorldChange: Boolean read FListenWorldChange write SetListenWorldChange;
Public property AngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity;
Public property LinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity;
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: TCollisionEvent read FOnCollisionEnter write SetOnCollisionEnter;
Public property OnCollisionExit: TCollisionEvent read FOnCollisionExit write SetOnCollisionExit;
Public property OnCollisionStay: TCollisionEvent read FOnCollisionStay write SetOnCollisionStay;
Published property Dynamic: Boolean read FDynamic write SetDynamic default true;
Published property Animated: Boolean read FAnimated write SetAnimated default false;
Published property Trigger: Boolean read FTrigger write SetTrigger default false;
Published property CollisionDetection: TCollisionDetection read FCollisionDetection write SetCollisionDetection default cdDiscrete;
Published property Layer: TPhysicsLayer read FLayer write SetLayer default 0;
Published property Gravity: Boolean read FGravity write SetGravity default true;
Published property LockTranslation: T3DCoords read FLockTranslation write SetLockTranslation default [];
Published property LockRotation: T3DCoords read FLockRotation write SetLockRotation default [];
Published property Exists: Boolean read FExists write SetExists default true;
Published property AngularVelocityDamp: Single read FAngularVelocityDamp write SetAngularVelocityDamp default 0.1;
Published property MaxAngularVelocity: Single read FMaxAngularVelocity write SetMaxAngularVelocity;
Published property LinearVelocityDamp: Single read FLinearVelocityDamp write SetLinearVelocityDamp default 0.1;
Published property MaxLinearVelocity: Single read FMaxLinearVelocity write SetMaxLinearVelocity;
Published property AngularVelocityPersistent: TCastleVector3Persistent read FAngularVelocityPersistent ;
Published property LinearVelocityPersistent: TCastleVector3Persistent read FLinearVelocityPersistent ;

Description

Methods

Protected function GetInternalText: String; virtual;

This item has no description.

Source: base/castleclassutils.pas (line 575).

Protected procedure SetInternalText(const Value: String); virtual;

This item has no description.

Source: base/castleclassutils.pas (line 576).

Protected procedure SetName(const Value: TComponentName); override;

This item has no description.

Source: base/castleclassutils.pas (line 577).

Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual;

Enumerate all properties that are possible to translate in this component. E.g. in TCastleLabel it will return TCastleLabel.Caption, in TCastleEdit it will return TCastleEdit.Text and TCastleEdit.Placeholder.

Returns only non-empty properties, thus assuming that if current (by convention, English) text is empty, then there is no point in translating it. Moreover descendants may define boolean properties to exclude particular text from translating, e.g. TCastleLabel.CaptionTranslate, TCastleEdit.TextTranslate, TCastleEdit.PlaceholderTranslate.

It is not recursive (it doesn't enumerate children properties). Use global TranslateProperties procedure to call this on a hierarchy of TComponent.

You usually don't want to call this method (it is called by other engine routines). But you may find it useful to override this, if you define new component.

Source: base/castleclassutils.pas (line 598).

Public destructor Destroy; override;

This item has no description.

Source: base/castleclassutils.pas (line 604).

Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual;

Override this method to call various methods of SerializationProcess, which in turn allows to serialize/deserialize things that are not published. This allows to serialize/deserialize with more freedom, e.g. to serialize/deserialize some private field.

Source: base/castleclassutils.pas (line 610).

Public function PropertySections(const PropertyName: String): TPropertySections; virtual;

Section where to show property in the editor.

Source: base/castleclassutils.pas (line 631).

Public procedure SetTransient;

Ignore this component when serializing parent's TCastleUserInterface.Controls list or TCastleTransform.List, and do not show this component in CGE editor. This simply sets csTransient flag in ComponentStyle.

This is useful for children that are automatically managed by the parent, and should not be modified by user code. For example, TCastleCheckbox is internally composed from TCastleImageControl and TCastleLabel children, but we don't want to serialize or even show these children to user.

Note that if you want to prevent this component from serializing as part of TCastleUserInterface.Controls list or TCastleTransform.List, but you still want it to be visible in CGE editor, then make it a "subcomponent" instead, by SetSubComponent(true).

Note that both csSubComponent and csTransient only disable the component serialization as part of parent's lists enumerated by CustomSerialization (see internal TCastleUserInterface.SerializeChildrenEnumerate , TCastleTransform.SerializeChildrenEnumerate, TCastleTransform.SerializeBehaviorsEnumerate).

If you will make the component published in its own property (which is normal for "subcomponents") then it will be serialized anyway, just as part of it's own property (like TCastleScrollView.ScrollArea). So to really avoid serializing a children component make it csSubComponent and/or csTransient, and do not publish it.

Source: base/castleclassutils.pas (line 663).

Public procedure AddNonVisualComponent(const NonVisualComponent: TComponent);

Add non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.

See also
NonVisualComponentsCount
Count of components added by AddNonVisualComponent.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 672).

Public procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent);

Insert non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.

See also
NonVisualComponentsCount
Count of components added by AddNonVisualComponent.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 681).

Public procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent);

Removes the component previously added by AddNonVisualComponent.

Source: base/castleclassutils.pas (line 684).

Public function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer;

Index of the previously added non-visual component. Returns -1 if the component was not found.

Source: base/castleclassutils.pas (line 688).

Public function NonVisualComponentsCount: Integer;

Count of components added by AddNonVisualComponent.

See also
AddNonVisualComponent
Add non-visual component to this component.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 695).

Public function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator;

You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do .... Do not call this method in other contexts, it is only useful for "for..in" construction.

See also
AddNonVisualComponent
Add non-visual component to this component.

Source: base/castleclassutils.pas (line 705).

Public function ValueIsStreamed: Boolean; virtual;

Whether the current value of this object should be written to the stream. This should be True if anything inside this object should be serialized (which means it has non-default value or "stored" specifier indicates that it should be serialized).

This is used by CastleComponentSerialize, which is used in Castle Game Engine for all serialization.

In simple cases, this just says whether the current value of this object equals to some default value.

The default implementation of this class returns True (so always write).

Descendants that override this to sometimes return False (so no need to write) must be very careful: any addition of a new field requires extending this method, otherwise new field may not be saved sometimes (when all other fields are default). Descentants of such classes must also be aware of it. This check must include everything that is inside this object in JSON, including subcomponents and children objects (as done e.g. by TSerializationProcess.ReadWriteList). In practice, overriding this method is only reasonable for simple classes that will not change much in the future, like TCastleVector3Persistent.

The name of this method is consistent with TPropertyEditor.ValueIsStreamed in LCL.

Source: base/castleclassutils.pas (line 739).

Public procedure DesignerInfo(const SList: TStrings); virtual;

Override to add information that should be visible at design-time. Call SList.Add for each new line of information.

Source: base/castleclassutils.pas (line 743).

Public procedure DesignerWarnings(const SList: TStrings); virtual;

Override to add warnings that should be visible at design-time. Call SList.Add for each new warning.

Source: base/castleclassutils.pas (line 747).

Protected procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual;

Continuously occuring event, for various tasks.

Parameters
RemoveMe
Set this to rtRemove or rtRemoveAndFree to remove this component from Parent after this call finished. rtRemoveAndFree additionally will free this item. Initially it's rtNone when this method is called.

Source: transform/castletransform_behavior.inc (line 52).

Protected procedure BeforeRender( const CameraView: TViewVectors; const ParentParentWorldTransformation: TTransformation); virtual;

Event called right before rendering the parent TCastleTransform. Override this if you have to adjust the parent transformation strictly before the rendering.

Compared to adjusting the parent transformation in e.g. Update, adjusting the parent transformation here has advantages:

  1. There's no 1-frame delay between moving the thing that causes the change (like camera) and updating the thing that reacts to it (like a transformation with a billboard).

  2. We adjust transformation before rendering each occurrence of TCastleTransform in the viewport tree. This matters if given TCastleTransform may occur multiple times in the viewport tree, directly or through TCastleTransformReference.

  3. We adjust transformation before each render, so things are OK if given TCastleTransform is present in multiple viewports (see https://castle-engine.io/multiple_viewports_to_display_one_world).

For example, adjusting the TCastleTransform done by the TCastleBillboard is done using this method. The transformation in this case is determined by the camera and parent's parent transformation. The transformation has to be applied without any delay (even a 1-frame delay would be visible, as artifacts caused by billboard not perfectly aligned with the camera would be visible – blending sort along camera direction in sort3D is not perfect if billboard doesn't exactly match camera direction). And the transformation with billboard may be present in multiple viewports and/or multiple times in the same viewport tree.

Parameters
CameraView
Current camera vectors, in world coordinates, used to render the scene now.
ParentParentWorldTransformation

World transformation of the parent of the parent of this behavior. The name is kind of convoluted, but consistent: When the parent of this behavior has exactly one parent TCastleTransform (not zero, not more) then ParentParentWorldTransformation.Transform is equivalent to Parent.Parent.WorldTransform.

Source: transform/castletransform_behavior.inc (line 103).

Protected procedure ParentChanged; virtual; deprecated 'Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach';

Warning: this symbol is deprecated: Use ParentAfterAttach / ParentBeforeDetach or WorldAfterAttach / WorldBeforeDetach

Called after Parent changed, at the end of TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior.

Source: transform/castletransform_behavior.inc (line 109).

Protected procedure ParentAfterAttach; virtual;

Called after Parent changed, e.g. at the end of TCastleTransform.AddBehavior.

Source: transform/castletransform_behavior.inc (line 113).

Protected procedure ParentBeforeDetach; virtual;

Called before Parent changed, e.g. at the beginning of TCastleTransform.RemoveBehavior.

This is also called at the destruction of behavior (more precisely from BeforeDestruction now). Even in this case, we guarantee that Parent is still valid during this call, and not in half-destroyed state. Before the actual destructor of TCastleBehavior we do BeforeParentDetach and BeforeWorldDetach and set Parent to Nil.

Source: transform/castletransform_behavior.inc (line 122).

Protected procedure WorldAfterAttach; virtual;

Called after Parent became part of World. Called only if ListenWorldChange is True.

Source: transform/castletransform_behavior.inc (line 126).

Protected procedure WorldBeforeDetach; virtual;

Called before Parent stops being part of World. Called only if ListenWorldChange is True.

This is also called at the destruction of behavior (more precisely from BeforeDestruction now). Even in this case, we guarantee that Parent is still valid during this call, and not in half-destroyed state. Before the actual destructor of TCastleBehavior we do BeforeParentDetach and BeforeWorldDetach and set Parent to Nil.

Source: transform/castletransform_behavior.inc (line 136).

Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; virtual;

Check can this behavior be added to NewParent. When this returns False, it has to set also ReasonWhyCannot. When overriding this, you can use e.g. this code to make sure we are the only behavior of given class:

function TCastleBillboard.CanAttachToParent(const NewParent: TCastleTransform;
  out ReasonWhyCannot: String): Boolean;
begin
  Result := inherited;
  if not Result then Exit;

  if NewParent.FindBehavior(TCastleBillboard) <> nil then
  begin
    ReasonWhyCannot := 'Only one TCastleBillboard behavior can be added to a given TCastleTransform';
    Result := false;
  end;
end;

Source: transform/castletransform_behavior.inc (line 158).

Public procedure BeforeDestruction; override;

This item has no description.

Source: transform/castletransform_behavior.inc (line 161).

Public function World: TCastleAbstractRootTransform;

Reference to the root transformation (typically matching the TCastleViewport.Items value) corresponding to the parent of this behavior.

May be Nil if the behavior is not yet added to the parent TCastleTransform, or when the TCastleTransform is not yet part of the TCastleAbstractRootTransform (which means that TCastleTransform is not added to the viewport yet). You can use ListenWorldChange and override WorldBeforeDetach, WorldAfterAttach to be notified when this changes.

Source: transform/castletransform_behavior.inc (line 184).

Protected procedure WorldAfterAttach; override;

Initializes physics engine objects when TCastleRigidBody is attached to world.

Source: transform/castletransform_physics.inc (line 873).

Protected procedure WorldBeforeDetach; override;

Deinitializes physics engine objects when TCastleRigidBody is attached to world.

Source: transform/castletransform_physics.inc (line 877).

Protected procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;

This item has no description. Showing description inherited from TCastleBehavior.Update.

Continuously occuring event, for various tasks.

Source: transform/castletransform_physics.inc (line 878).

Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;

Only one TCastleRigidBody behavior can be added to a given TCastleTransform so we check that here.

Source: transform/castletransform_physics.inc (line 882).

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Source: transform/castletransform_physics.inc (line 885).

Public destructor Destroy; override;

This item has no description.

Source: transform/castletransform_physics.inc (line 886).

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.

Source: transform/castletransform_physics.inc (line 891).

Public function GetCollidingTransforms: TCastleTransformList;

Transformations that we collide with currently.

Source: transform/castletransform_physics.inc (line 894).

Public function PhysicsRayCast(const RayOrigin, RayDirection: TVector3; const MaxDistance: Single = MaxSingle; const CollisionLayers: TPhysicsLayers = AllLayers): TRayCastResult;

First object hit by the ray, calculated using the physics engine.

Returns the TRayCastResult record. Read TRayCastResult.Hit (boolean), TRayCastResult.Transform (guaranteed to be Nil when TRayCastResult.Hit is False) and other fields to know what was hit.

The given RayOrigin, RayDirection, MaxDistance are in the parent coordinate system of associated TCastleTransform. For example query like this works naturally:

// MyTransform.Translation, MyTransform.Direction
// are in MyTransform.Parent coordinate system
Hit := MyTransform.RigidBody.PhysicsRayCast(
  MyTransform.Translation,
  MyTransform.Direction, MaxDistance);

It returns TRayCastResult, with information there consistently in the same coordinate system as inputs. So TRayCastResult.Distance, TRayCastResult.Point, TRayCastResult.Normal are also in parent coordinate system of associated TCastleTransform.

Collisions taken / not taken into account:

  • Ignores the collider of this rigid body, to not accidentally collide with your own collider.

  • Ignores collisions beyond MaxDistance, if MaxDistance <> MaxSingle. Passing some MaxDistance may also optimize the calculation.

  • Only collisions with the physics colliders (TCastleCollider) are considered.

By default, the ray hits all physics layers, but you can choose physics layers in CollisionLayers attribute.

Note: The TCastleTransform.Pickable property is ignored by this method, i.e. it considers all colliders regardless of their TCastleTransform.Pickable value. The TCastleTransform.Pickable is only taken into account by the routines of the old physics system (see https://castle-engine.io/physics#_old_system_for_collisions_and_gravity ). In the new system, a similar role is filled by physics layers.

Source: transform/castletransform_physics.inc (line 940).

Public function PhysicsSphereCast(const SphereOrigin: TVector3; const SphereRadius:Single; const SphereDirection: TVector3; const MaxDistance: Single = MaxSingle; const CollisionLayers: TPhysicsLayers = AllLayers): TRayCastResult;

Check if moving a sphere in the given direction would collide with anything in the world. Suitable to check if moving this rigid body, approximating this body as a sphere, would collide with anything.

Returns the TRayCastResult record. Read TRayCastResult.Hit (boolean), TRayCastResult.Transform (guaranteed to be Nil when TRayCastResult.Hit is False) and other fields to know what was hit.

The given SphereOrigin, SphereRadius, SphereDirection, MaxDistance are in the parent coordinate system of associated TCastleTransform. For example query like this works naturally:

// MyTransform.Translation, MyTransform.Direction
// are in MyTransform.Parent coordinate system
Hit := MyTransform.RigidBody.PhysicsSphereCast(
  MyTransform.Translation, 2,
  MyTransform.Direction, MaxDistance);

It returns TRayCastResult, with information there consistently in the same coordinate system as inputs. So TRayCastResult.Distance, TRayCastResult.Point, TRayCastResult.Normal are also in parent coordinate system of associated TCastleTransform.

Collisions taken / not taken into account:

  • Ignores all colliders that overlap sphere at the initial position, before it is moved by SphereDirection.

  • Always ignores the collider of this rigid body, to not accidentally collide with your own collider.

  • Ignores collisions that would occur is sphere is moved by move than MaxDistance, if MaxDistance <> MaxSingle. Passing some MaxDistance may also optimize the calculation.

  • Only collisions with the physics colliders (TCastleCollider) are considered.

By default, the sphere hits all physics layers, but you can choose physics layers in CollisionLayers attribute.

Note: The TCastleTransform.Pickable property is ignored by this method, i.e. it considers all colliders regardless of their TCastleTransform.Pickable value. The TCastleTransform.Pickable is only taken into account by the routines of the old physics system (see https://castle-engine.io/physics#_old_system_for_collisions_and_gravity ). In the new system, a similar role is filled by physics layers.

Source: transform/castletransform_physics.inc (line 995).

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Source: transform/castletransform_physics.inc (line 1000).

Public procedure AddForceAtPosition(const Force, Position: TVector3);

Push this rigid body. The body is pushed from a Position and along the direction of Force. Longer length of Force makes a stronger push.

The forces affecting each body are reset every frame (only the body velocity is preserved across frames). If you want to keep applying this force (e.g. it is a wind that continues pushing in given direction) you should call this method every frame. It automatically accounts for the delta time (because the force will actually be applied later, with delta time, to velocity) so no need to multiply the arguments with SecondsPassed. That is, adding force means Velocity += Force * SecondsPassed / Mass.

By changing Position from which you push, you can change the angular velocity, i.e. different Position makes the body spin in different ways. Note that Position too distant from the body center may result in unrealistically strong push. If Position is exactly at body center, then angular velocity will not be affected.

Force and Position are in the world coordinate system.

Source: transform/castletransform_physics.inc (line 1021).

Public procedure AddForce(const Force: TVector3; const ForceInLocalCoordinates: Boolean);

Push this rigid body. The body is pushed along the direction of Force. Longer length of Force makes a stronger push.

This is similar to AddForceAtPosition, but the Force (direction) can be in local or global coordinate system (depending on ForceInLocalCoordinates). Moreover it doesn't take as parameter any Position: the force always acts from the origin of this body.

Just like with AddForceAtPosition, the forces affecting each body are reset every frame (only the body velocity is preserved across frames). If you want to keep applying this force (e.g. it is a wind that continues pushing in given direction) you should call this method every frame. It automatically accounts for the delta time (because the force will actually be applied later, with delta time, to velocity) so no need to multiply the arguments with SecondsPassed.

Source: transform/castletransform_physics.inc (line 1040).

Public procedure AddTorque(const Torque: TVector3);

Rotate this rigid body with physics. Longer length of Torque makes a stronger push. Torque is in world coordinates.

Just like with AddForceAtPosition, the forces affecting each body are reset every frame (only the body velocity is preserved across frames). If you want to keep applying this force (e.g. it is a whirlwind that continues rotating) you should call this method every frame. It automatically accounts for the delta time (because the force will actually be applied later, with delta time, to velocity) so no need to multiply the arguments with SecondsPassed.

Source: transform/castletransform_physics.inc (line 1053).

Public procedure ApplyImpulse(const Impulse, Point: TVector3);

Apply a one-time instant increase in speed, that pushes the body (increasing velocity). Impulse is a direction along which to push, Point is the position from which you push. Longer length of Impulse makes a stronger push.

Impulse and Point are both in world coordinates.

Adding impulse means Velocity += Force / Mass. To be more precise, adding impulse directly increases LinearVelocity and AngularVelocity. Unlike AddForceAtPosition, the velocity increase is not multiplied by the delta of time, so it is not expected you will call this every frame. (If you do, you should take care to multiply Impulse by SecondsPassed.)

Same notes as for Position of AddForceAtPosition: By changing Point from which you push, you can change the angular velocity, i.e. different Point makes the body spin in different ways. Note that Point too distant from the body center may result in unrealistically strong push. If Point is exactly at body center, then angular velocity will not be affected.

Source: transform/castletransform_physics.inc (line 1073).

Public function ExistsInRoot: Boolean;

Returns true when rigid body behavior exists, and is added to Castle Transform, and this transform ExistsInRoot = true.

Source: transform/castletransform_physics.inc (line 1077).

Public procedure WakeUp;

For performance reasons, physics engine puts the body to "sleep" when it didn't move (too much) in the recent frames. This means the body will not move anymore "by itself", i.e. until something will collide with it. In general, the body should be "woken up" automatically when something collides with it, so the mechanism should be invisible to you, but sometimes it is necessary to wake up a body explicitly.

Source: transform/castletransform_physics.inc (line 1086).

Public function Awake: Boolean;

For performance reasons, physics engine puts the body to "sleep" when it didn't move (too much) in the recent frames. Use this to read current state.

Source: transform/castletransform_physics.inc (line 1093).

Properties

Public property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents;

Components added by AddNonVisualComponent.

Source: base/castleclassutils.pas (line 698).

Public property IsLoading: Boolean read FIsLoading;

Is the component during deserialization now.

Note: We can't use csLoading in ComponentState because in Delphi it is not possible to control it from CastleComponentSerialize.

Source: base/castleclassutils.pas (line 711).

Public property Parent: TCastleTransform read FParent;

Parent TCastleTransform of this behavior. Change it by doing TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior.

Nil if this behavior is not yet added to a parent.

Source: transform/castletransform_behavior.inc (line 191).

Public property ListenWorldChange: Boolean read FListenWorldChange write SetListenWorldChange;

Set this to True to receive WorldBeforeDetach, WorldAfterAttach calls.

Source: transform/castletransform_behavior.inc (line 194).

Public property AngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity;

Current rotating velocity of this body. You can query it (as it changes, affected by forces) and set it at any point. In world coordinates.

See https://en.wikipedia.org/wiki/Angular_velocity about the exact meaning of angular velocity. The vector direction (AngularVelocity.Normalize) determines the axis around which we rotate. The vector length (AngularVelocity.Length) determines the speed (in radians/second) with which we rotate.

Source: transform/castletransform_physics.inc (line 1104).

Public property LinearVelocity: TVector3 read FLinearVelocity write SetLinearVelocity;

Current moving velocity of this body. You can query it (as it changes, affected by forces) and set it at any point. In world coordinates.

Source: transform/castletransform_physics.inc (line 1109).

Public property InitialAngularVelocity: TVector3 read FAngularVelocity write SetAngularVelocity; deprecated 'use AngularVelocity';

Warning: this symbol is deprecated: use AngularVelocity

This item has no description.

Source: transform/castletransform_physics.inc (line 1112).

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

Warning: this symbol is deprecated: use LinearVelocity

This item has no description.

Source: transform/castletransform_physics.inc (line 1114).

Public property OnCollisionEnter: TCollisionEvent read FOnCollisionEnter write SetOnCollisionEnter;

Occurs when TCastleRigidBody starts colliding with another TCastleRigidBody.

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 related TCastleTransform or TCastleRigidBody or TCastleCollider components upon receiving this event. Right now, it would free an underlying physics engine object, and this would crash the physics engine.

Instead, you can:

Source: transform/castletransform_physics.inc (line 1139).

Public property OnCollisionExit: TCollisionEvent read FOnCollisionExit write SetOnCollisionExit;

Occurs when TCastleRigidBody stops colliding with another TCastleRigidBody.

Just like at OnCollisionEnter: Do not free the related components upon receiving this event. See the OnCollisionEnter documentation for details of this limitation and solutions.

Source: transform/castletransform_physics.inc (line 1147).

Public property OnCollisionStay: TCollisionEvent read FOnCollisionStay write SetOnCollisionStay;

Occurs when TCastleRigidBody still collides with another TCastleRigidBody.

Just like at OnCollisionEnter: Do not free the related components upon receiving this event. See the OnCollisionEnter documentation for details of this limitation and solutions.

Source: transform/castletransform_physics.inc (line 1155).

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

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

When False the object is not transformed by the physics simulation. It still collides with other physical objects. So it's a static collidable body that will not move on any collision / force.

Source: transform/castletransform_physics.inc (line 1163).

Published property Animated: Boolean read FAnimated write SetAnimated 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.

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 the transformation 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.

Source: transform/castletransform_physics.inc (line 1194).

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: (TCastleRigidBody.OnCollisionEnter, TCastleRigidBody.OnCollisionStay, TCastleRigidBody.OnCollisionExit).

Source: transform/castletransform_physics.inc (line 1207).

Published property CollisionDetection: TCollisionDetection read FCollisionDetection write SetCollisionDetection default cdDiscrete;

Sets CollisionDetectionMode in rigid body to Discrete or ContinuousSweep.

Source: transform/castletransform_physics.inc (line 1210).

Published property Layer: TPhysicsLayer read FLayer write SetLayer default 0;

Physics layer of the rigid body determines with which other bodies it may collide.

The way layers interact is configured in the MyViewport.Items.PhysicsProperties.LayerCollisions.

Each layer can also have name and description. You can set them using the MyViewport.Items.PhysicsProperties.LayerNames property.

Source: transform/castletransform_physics.inc (line 1222).

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

Is this object affected by gravity.

Source: transform/castletransform_physics.inc (line 1225).

Published property LockTranslation: T3DCoords read FLockTranslation write SetLockTranslation default [];

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.

Source: transform/castletransform_physics.inc (line 1233).

Published property LockRotation: T3DCoords read FLockRotation write SetLockRotation default [];

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.

Source: transform/castletransform_physics.inc (line 1241).

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, it does not cause collisions with other rigid bodies and it does not receive events like OnCollisionEnter, OnCollisionStay, OnCollisionExit.

Source: transform/castletransform_physics.inc (line 1248).

Published property AngularVelocityDamp: Single read FAngularVelocityDamp write SetAngularVelocityDamp default 0.1;

Damping means that the velocity will decrease over time. AngularVelocityDamp causes AngularVelocity to decrease over time. For the exact equations how it works, see LinearVelocityDamp.

Source: transform/castletransform_physics.inc (line 1253).

Published property MaxAngularVelocity: Single read FMaxAngularVelocity write SetMaxAngularVelocity;

This item has no description.

Source: transform/castletransform_physics.inc (line 1254).

Published property LinearVelocityDamp: Single read FLinearVelocityDamp write SetLinearVelocityDamp default 0.1;

Damping means that the velocity will decrease over time. LinearVelocityDamp causes LinearVelocity to decrease over time, similar AngularVelocityDamp causes AngularVelocity to decrease over time.

Values from 0.0 up to infinity make sense.

Exact interpretation:

The damping is applied every "physics frame" following this equation:

LinearVelocity := LinearVelocity * 1 / (1 + LinearVelocityDamp * 1/PhysicsProperties.Frequency)

Where PhysicsProperties.Frequency is by default 60, and can be customized for each viewport using Viewport.Items.PhysicsProperties.Frequency. The frequency also determines how often do "physics frames" occur.

In effect, damping = 0 means that no damping occurs.

Damping values > 0 means that LinearVelocity decreases with time, larger LinearVelocityDamp -> the faster LinearVelocity will decrease.

The meaning of damping = 1.0 depends on Viewport.Items.PhysicsProperties.Frequency:

  • With TPhysicsProperties.Frequency = 60 (default), the XxxVelocityDamp = 1.0 implies that the velocity drops to ~0.37 of original after 1 second.

  • With TPhysicsProperties.Frequency = 1 (crazy small, just giving it as example), the XxxVelocityDamp = 1.0 implies that the velocity drops to half of original after 1 second.

  • With TPhysicsProperties.Frequency = 10000 (crazy large, just giving it as example), the XxxVelocityDamp = 1.0 implies that the velocity drops to ~0.36 of original after 1 second.

Source: transform/castletransform_physics.inc (line 1294).

Published property MaxLinearVelocity: Single read FMaxLinearVelocity write SetMaxLinearVelocity;

This item has no description.

Source: transform/castletransform_physics.inc (line 1295).

Published property AngularVelocityPersistent: TCastleVector3Persistent read FAngularVelocityPersistent ;

AngularVelocity that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write AngularVelocity directly.

See also
AngularVelocity
Current rotating velocity of this body.

Source: transform/auto_generated_persistent_vectors/tcastlerigidbody_persistent_vectors.inc (line 37).

Published property LinearVelocityPersistent: TCastleVector3Persistent read FLinearVelocityPersistent ;

LinearVelocity that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write LinearVelocity directly.

See also
LinearVelocity
Current moving velocity of this body.

Source: transform/auto_generated_persistent_vectors/tcastlerigidbody_persistent_vectors.inc (line 105).


Generated by PasDoc 0.17.0.snapshot.