Dawn/src/dawn/scene/components/physics/3d/CharacterController3D.cpp

35 lines
915 B
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "CharacterController3D.hpp"
using namespace Dawn;
CharacterController3D::CharacterController3D(SceneItem *item) :
SceneItemComponent(item)
{
}
void CharacterController3D::onStart() {
useEvent([&](float_t delta){
// Friction
velocity -= glm::vec3(velocity.x, 0, velocity.z) * friction * delta;
// Gravity
velocity += this->gravity * delta;
auto myCollider = item->getComponent<Collider3D>();
auto colliders = getScene()->findComponents<Collider3D>();
auto itCollider = colliders.begin();
// while(itCollider != colliders.end()) {
// (*itCollider)->
// ++itCollider;
// }
// Move / Update
transform->setLocalPosition(transform->getLocalPosition() + (velocity * delta));
}, getScene()->eventSceneUpdate);
}