MoveComponent handles the movement logic for an actor. It applies forces, updates position and rotation, and integrates basic physics like gravity and friction. Also supports collision detection via an optional collider component.
More...
#include <MoveComponent.h>
|
| MoveComponent (Actor *pOwner, int pUpdateOrder=100) |
| Constructor for MoveComponent.
|
|
| MoveComponent ()=delete |
|
| MoveComponent (const MoveComponent &)=delete |
|
MoveComponent & | operator= (const MoveComponent &)=delete |
|
Vector3 | GetSpeed () const |
| Gets the current speed of the actor.
|
|
void | SetSpeed (Vector3 pSpeed) |
| Sets the actor's speed.
|
|
void | AddForce (Vector3 pForce) |
| Adds a force to the actor's velocity.
|
|
Vector2 | GetRotationSpeed () const |
| Gets the current rotation speed of the actor.
|
|
void | SetRotationSpeed (Vector2 pRotationSpeed) |
| Sets the rotation speed of the actor.
|
|
virtual void | Update () override |
| Updates the position, rotation, and velocity of the actor each frame. Applies gravity, friction, rotation, and checks for collisions.
|
|
virtual Vector3 | GetDesiredPos () |
| Computes the desired position of the actor after applying speed and velocity. Also handles collision detection along the X, Y, and Z axes.
|
|
void | SetCollider (ColliderComponent *pCollider) |
| Sets the collider for collision detection.
|
|
ColliderComponent * | CheckCollision () |
| Checks for a collision with other colliders in the scene. If a collision is detected, applies a simple collision response.
|
|
| Component (Actor *pOwner, int pUpdateOrder=100) |
| Constructor for Component.
|
|
virtual | ~Component () |
|
virtual void | OnStart () |
| Called when the component is initialized (during actor start). This can be used to perform any setup operations for the component.
|
|
virtual void | OnEnd () |
| Called when the component is about to be destroyed (during actor destruction). This can be used to clean up or release any resources.
|
|
virtual void | OnUpdateWorldTrandform () |
| Called when the world transform of the actor is updated. This allows the component to react to changes in the actor's world transform.
|
|
void | SetActive (bool isActive) |
| Sets the active status of the component.
|
|
void | SetOwner (Actor *pOwner) |
| Sets the actor that owns this component.
|
|
int | GetUpdateOrder () const |
| Returns the update order of the component. Components with lower update orders are updated first.
|
|
Actor * | GetOwner () const |
| Returns the actor that owns this component.
|
|
MoveComponent handles the movement logic for an actor. It applies forces, updates position and rotation, and integrates basic physics like gravity and friction. Also supports collision detection via an optional collider component.
◆ MoveComponent() [1/3]
MoveComponent::MoveComponent |
( |
Actor * | pOwner, |
|
|
int | pUpdateOrder = 100 ) |
Constructor for MoveComponent.
- Parameters
-
pOwner | The actor that owns this component. |
pUpdateOrder | Order in which the component will be updated (default: 100). |
◆ MoveComponent() [2/3]
MoveComponent::MoveComponent |
( |
| ) |
|
|
delete |
◆ MoveComponent() [3/3]
◆ AddForce()
void MoveComponent::AddForce |
( |
Vector3 | pForce | ) |
|
Adds a force to the actor's velocity.
- Parameters
-
pForce | The force to add to the velocity. |
◆ CheckCollision()
Checks for a collision with other colliders in the scene. If a collision is detected, applies a simple collision response.
- Returns
- The collider component that was collided with, or nullptr if no collision.
◆ GetDesiredPos()
Vector3 MoveComponent::GetDesiredPos |
( |
| ) |
|
|
virtual |
Computes the desired position of the actor after applying speed and velocity. Also handles collision detection along the X, Y, and Z axes.
- Returns
- The calculated desired position after checking for collisions.
◆ GetRotationSpeed()
Vector2 MoveComponent::GetRotationSpeed |
( |
| ) |
const |
Gets the current rotation speed of the actor.
- Returns
- The actor's rotation speed as a Vector2 (x for yaw, y for pitch).
◆ GetSpeed()
Vector3 MoveComponent::GetSpeed |
( |
| ) |
const |
Gets the current speed of the actor.
- Returns
- The actor's speed in 3D space as a Vector3.
◆ operator=()
◆ SetCollider()
Sets the collider for collision detection.
- Parameters
-
pCollider | Collider component to be used for collision checks. |
◆ SetRotationSpeed()
void MoveComponent::SetRotationSpeed |
( |
Vector2 | pRotationSpeed | ) |
|
Sets the rotation speed of the actor.
- Parameters
-
pRotationSpeed | The new rotation speed to set. |
◆ SetSpeed()
void MoveComponent::SetSpeed |
( |
Vector3 | pSpeed | ) |
|
Sets the actor's speed.
- Parameters
-
pSpeed | New speed to be set. |
◆ Update()
void MoveComponent::Update |
( |
| ) |
|
|
overridevirtual |
Updates the position, rotation, and velocity of the actor each frame. Applies gravity, friction, rotation, and checks for collisions.
Reimplemented from Component.
Reimplemented in EditorController.
◆ mFriction
float MoveComponent::mFriction = 0.8f |
Friction coefficient applied to velocity each update.
◆ mGravityDirection
Direction of gravity applied to the actor. Default is a zero vector (no gravity).
◆ mRotationSpeed
Vector2 MoveComponent::mRotationSpeed = 0 |
|
protected |
Rotation speed of the actor (yaw and pitch).
◆ mSpeed
Speed of the actor in 3D space (can be adjusted to control movement).
◆ mVelocity
Current velocity of the actor in 3D space.
The documentation for this class was generated from the following files: