28 lines
619 B
C++
28 lines
619 B
C++
#include "components/PhysicsComponent.hpp"
|
|
|
|
#include "Entity.hpp"
|
|
#include "components/TransformComponent.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
void PhysicsComponent::Setup() {}
|
|
|
|
void PhysicsComponent::Update(float dt) {
|
|
auto transform = entity->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
|
|
const float speed = std::sqrt(vx * vx + vy * vy);
|
|
if (speed > speedCap && speed > 0.0f) {
|
|
const float scale = speedCap / speed;
|
|
vx *= scale;
|
|
vy *= scale;
|
|
}
|
|
|
|
transform->get().x += vx * dt;
|
|
transform->get().y += vy * dt;
|
|
}
|
|
|
|
void PhysicsComponent::Cleanup() {}
|