Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
MoveComponent Class Reference

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>

Inheritance diagram for MoveComponent:
Component EditorController PlayerController

Public Member Functions

 MoveComponent (Actor *pOwner, int pUpdateOrder=100)
 Constructor for MoveComponent.
 
 MoveComponent ()=delete
 
 MoveComponent (const MoveComponent &)=delete
 
MoveComponentoperator= (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.
 
ColliderComponentCheckCollision ()
 Checks for a collision with other colliders in the scene. If a collision is detected, applies a simple collision response.
 
- Public Member Functions inherited from Component
 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.
 
ActorGetOwner () const
 Returns the actor that owns this component.
 

Public Attributes

Vector3 mGravityDirection = Vector3::Zero
 Direction of gravity applied to the actor. Default is a zero vector (no gravity).
 
Vector3 mVelocity = Vector3::Zero
 Current velocity of the actor in 3D space.
 
float mFriction = 0.8f
 Friction coefficient applied to velocity each update.
 

Protected Attributes

Vector3 mSpeed = 0
 Speed of the actor in 3D space (can be adjusted to control movement).
 
Vector2 mRotationSpeed = 0
 Rotation speed of the actor (yaw and pitch).
 
- Protected Attributes inherited from Component
ActormOwner = nullptr
 The actor that owns this component.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MoveComponent() [1/3]

MoveComponent::MoveComponent ( Actor * pOwner,
int pUpdateOrder = 100 )

Constructor for MoveComponent.

Parameters
pOwnerThe actor that owns this component.
pUpdateOrderOrder in which the component will be updated (default: 100).

◆ MoveComponent() [2/3]

MoveComponent::MoveComponent ( )
delete

◆ MoveComponent() [3/3]

MoveComponent::MoveComponent ( const MoveComponent & )
delete

Member Function Documentation

◆ AddForce()

void MoveComponent::AddForce ( Vector3 pForce)

Adds a force to the actor's velocity.

Parameters
pForceThe force to add to the velocity.

◆ CheckCollision()

ColliderComponent * MoveComponent::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=()

MoveComponent & MoveComponent::operator= ( const MoveComponent & )
delete

◆ SetCollider()

void MoveComponent::SetCollider ( ColliderComponent * pCollider)

Sets the collider for collision detection.

Parameters
pColliderCollider component to be used for collision checks.

◆ SetRotationSpeed()

void MoveComponent::SetRotationSpeed ( Vector2 pRotationSpeed)

Sets the rotation speed of the actor.

Parameters
pRotationSpeedThe new rotation speed to set.

◆ SetSpeed()

void MoveComponent::SetSpeed ( Vector3 pSpeed)

Sets the actor's speed.

Parameters
pSpeedNew 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.

Member Data Documentation

◆ mFriction

float MoveComponent::mFriction = 0.8f

Friction coefficient applied to velocity each update.

◆ mGravityDirection

Vector3 MoveComponent::mGravityDirection = Vector3::Zero

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

Vector3 MoveComponent::mSpeed = 0
protected

Speed of the actor in 3D space (can be adjusted to control movement).

◆ mVelocity

Vector3 MoveComponent::mVelocity = Vector3::Zero

Current velocity of the actor in 3D space.


The documentation for this class was generated from the following files: