Skip to content

Commit

Permalink
demo - moving platform
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Nov 10, 2024
1 parent 327fad1 commit d1183d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Binary file modified data/maps/demo/demo.unv
Binary file not shown.
8 changes: 8 additions & 0 deletions data/maps/demo/platform.anp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
type = "Position X",
keyframes = [
0, 20, 50, 60, 70, 100, 120],
values = [
5.500000, 5.500000, -1.980000, -1.980000, -1.980000, 5.500000, 5.500000]
},

32 changes: 16 additions & 16 deletions src/physics/physics_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ struct PhysicsModuleImpl final : PhysicsModule
send(e2, e1);
}

// TODO move to lua plugin
void onControllerHit(EntityRef controller, EntityRef obj) {
if (!m_script_module) return;
if (!m_script_module->getWorld().hasComponent(controller, LUA_SCRIPT_TYPE)) return;
Expand Down Expand Up @@ -1695,8 +1696,7 @@ struct PhysicsModuleImpl final : PhysicsModule
void updateDynamicActors(bool vehicles)
{
PROFILE_FUNCTION();
for (EntityRef e : m_dynamic_actors)
{
for (EntityRef e : m_dynamic_actors) {
RigidActor& actor = m_actors[e];
m_update_in_progress = &actor;
PxTransform trans = actor.physx_actor->getGlobalPose();
Expand Down Expand Up @@ -1746,8 +1746,7 @@ struct PhysicsModuleImpl final : PhysicsModule
void updateControllers(float time_delta)
{
PROFILE_FUNCTION();
for (auto& controller : m_controllers)
{
for (auto& controller : m_controllers) {
Vec3 dif = controller.frame_change;
controller.frame_change = Vec3(0, 0, 0);

Expand All @@ -1764,24 +1763,23 @@ struct PhysicsModuleImpl final : PhysicsModule
}

bool apply_gravity = (state.collisionFlags & PxControllerCollisionFlag::eCOLLISION_DOWN) == 0;
if (apply_gravity)
{
if (apply_gravity) {
dif.y += controller.gravity_speed * time_delta;
controller.gravity_speed += time_delta * gravity_acceleration;
}
else
{
else {
controller.gravity_speed = 0;
// we need to apply gravity here otherwise the controller won't ride on horizontally moving platforms
dif.y = 0.5f * gravity_acceleration * time_delta * time_delta;
}

if (squaredLength(dif) > 0.00001f) {
m_filter_callback.m_filter_data = controller.filter_data;
PxControllerFilters filters(nullptr, &m_filter_callback);
controller.controller->move(toPhysx(dif), 0.001f, time_delta, filters);
PxExtendedVec3 p = controller.controller->getFootPosition();

m_world.setPosition(controller.entity, {p.x, p.y, p.z});
}
m_moving_controller = controller.entity;
m_filter_callback.m_filter_data = controller.filter_data;
PxControllerFilters filters(nullptr, &m_filter_callback);
controller.controller->move(toPhysx(dif), 0.001f, time_delta, filters);
PxExtendedVec3 p = controller.controller->getFootPosition();
m_world.setPosition(controller.entity, {p.x, p.y, p.z});
m_moving_controller = INVALID_ENTITY;
}
}

Expand Down Expand Up @@ -2458,6 +2456,7 @@ struct PhysicsModuleImpl final : PhysicsModule
}

void onControllerMoved(EntityRef entity) {
if (m_moving_controller == entity) return;
auto iter = m_controllers.find(entity);
ASSERT(iter.isValid());

Expand Down Expand Up @@ -3823,6 +3822,7 @@ struct PhysicsModuleImpl final : PhysicsModule

Array<EntityRef> m_dynamic_actors;
RigidActor* m_update_in_progress;
EntityPtr m_moving_controller = INVALID_ENTITY;
DelegateList<void(const ContactData&)> m_contact_callbacks;
bool m_is_game_running;
u32 m_debug_visualization_flags;
Expand Down

0 comments on commit d1183d7

Please sign in to comment.