X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2Fui.cpp;h=6a2e2ee167042720101bab5f7d1062d3c2cc610f;hb=916cba3b7b9dea6459febb90d24565cf4c0a8b2a;hp=1af9e8722f75cbc60c503b7882b6c187abde12a5;hpb=150d065f431d665326fd8028748c48a74ad956bb;p=blank.git diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 1af9e87..6a2e2ee 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -43,6 +43,12 @@ PlayerController::PlayerController(World &world, Player &player) player.GetEntity().SetController(*this); } +PlayerController::~PlayerController() { + if (&player.GetEntity().GetController() == this) { + player.GetEntity().UnsetController(); + } +} + void PlayerController::SetMovement(const glm::vec3 &m) noexcept { if (dot(m, m) > 1.0f) { move_dir = normalize(m); @@ -52,9 +58,8 @@ void PlayerController::SetMovement(const glm::vec3 &m) noexcept { Invalidate(); } -glm::vec3 PlayerController::ControlForce(const EntityState &s) const { - glm::vec3 target(rotateY(move_dir * player.GetEntity().MaxVelocity(), s.yaw) - s.velocity); - return target * player.GetEntity().MaxControlForce(); +glm::vec3 PlayerController::ControlForce(const Entity &e, const EntityState &s) const { + return TargetVelocity(rotateY(move_dir * e.MaxVelocity(), s.yaw), s, 5.0f); } void PlayerController::TurnHead(float dp, float dy) noexcept {