Skip to content

Commit

Permalink
Fix KinematicBody having a duplicate locked_axis variable
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Aug 26, 2021
1 parent 6e87d62 commit d96cbcd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
31 changes: 15 additions & 16 deletions scene/3d/physics_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, PhysicsServer3D::M
}
}

for (int i = 0; i < 3; i++) {
if (locked_axis & (1 << i)) {
r_result.travel[i] = 0;
}
}
_apply_axis_lock(r_result.travel);

if (!p_test_only) {
gt.origin += r_result.travel;
Expand All @@ -180,16 +176,23 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_motion
}

void PhysicsBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) {
if (p_lock) {
locked_axis |= p_axis;
} else {
locked_axis &= (~p_axis);
}
PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock);
}

bool PhysicsBody3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const {
return (locked_axis & p_axis);
return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis);
}

void PhysicsBody3D::_apply_axis_lock(Vector3 &p_motion) const {
if (get_axis_lock(PhysicsServer3D::BODY_AXIS_LINEAR_X)) {
p_motion.x = 0.0f;
}
if (get_axis_lock(PhysicsServer3D::BODY_AXIS_LINEAR_Y)) {
p_motion.y = 0.0f;
}
if (get_axis_lock(PhysicsServer3D::BODY_AXIS_LINEAR_Z)) {
p_motion.z = 0.0f;
}
}

Vector3 PhysicsBody3D::get_linear_velocity() const {
Expand Down Expand Up @@ -1085,11 +1088,7 @@ bool CharacterBody3D::move_and_slide() {
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
float delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();

for (int i = 0; i < 3; i++) {
if (locked_axis & (1 << i)) {
linear_velocity[i] = 0.0;
}
}
_apply_axis_lock(linear_velocity);

Vector3 current_floor_velocity = floor_velocity;
if ((on_floor || on_wall) && on_floor_body.is_valid()) {
Expand Down
3 changes: 1 addition & 2 deletions scene/3d/physics_body_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class PhysicsBody3D : public CollisionObject3D {

Ref<KinematicCollision3D> motion_cache;

uint16_t locked_axis = 0;

void _apply_axis_lock(Vector3 &p_motion) const;
Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_test_only = false, real_t p_margin = 0.001);

public:
Expand Down

0 comments on commit d96cbcd

Please sign in to comment.