32 m_lastCollisionNormal = normal;
33 m_hadCollision =
true;
40 transform->Translate(correction);
41 }
else if (
auto* cam =
dynamic_cast<Camera*
>(
owner)) {
42 cam->AddPosition(correction);
48 bool isGroundCollision = normal.
GetY() > 0.7f;
50 if (isGroundCollision) {
51 m_hadGroundCollision =
true;
52 m_groundNormal = normal;
56 if (m_velocity.GetY() < 0.0f) {
57 m_velocity =
Math::Vector3D(m_velocity.GetX(), 0.0f, m_velocity.GetZ());
60 m_hadWallCollision =
true;
61 m_wallNormal = normal;
64 float dot = m_velocity.
Dot(normal);
66 m_velocity = m_velocity - normal * dot;
void ClearCollisionState()
Resets HadCollision/HadGroundCollision/HadWallCollision for the next frame.
void Update(float deltaTime) override
RigidbodyComponent(GameObject *owner, BodyType type=BodyType::Kinematic)
bool Initialize() override
One-time setup, called after the component is attached and the owner is initialized.
void ResolveCollision(const Math::Vector3D &normal, float penetration)
Pushes the body out along normal by penetration and updates ground/wall collision state.