Merge pull request #45176 from aaronfranke/3.2-kine-dup-lock

[3.x] Fix KinematicBody axis lock
This commit is contained in:
Camille Mohr-Daurat 2021-08-30 09:11:44 -07:00 committed by GitHub
commit e44379612d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -144,6 +144,15 @@
</method>
</methods>
<members>
<member name="axis_lock_motion_x" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's X axis movement.
</member>
<member name="axis_lock_motion_y" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's Y axis movement.
</member>
<member name="axis_lock_motion_z" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's Z axis movement.
</member>
<member name="collision/safe_margin" type="float" setter="set_safe_margin" getter="get_safe_margin" default="0.001">
Extra margin used for collision recovery in motion functions (see [method move_and_collide], [method move_and_slide], [method move_and_slide_with_snap]).
If the body is at least this close to another body, it will consider them to be colliding and will be pushed away before performing the actual motion.
@ -154,13 +163,13 @@
If [code]true[/code], the body's movement will be synchronized to the physics frame. This is useful when animating movement via [AnimationPlayer], for example on moving platforms. Do [b]not[/b] use together with [method move_and_slide] or [method move_and_collide] functions.
</member>
<member name="move_lock_x" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's X axis movement.
Lock the body's X axis movement. Deprecated alias for [member axis_lock_motion_x].
</member>
<member name="move_lock_y" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's Y axis movement.
Lock the body's Y axis movement. Deprecated alias for [member axis_lock_motion_y].
</member>
<member name="move_lock_z" type="bool" setter="set_axis_lock" getter="get_axis_lock" default="false">
Lock the body's Z axis movement.
Lock the body's Z axis movement. Deprecated alias for [member axis_lock_motion_z].
</member>
</members>
<constants>

View file

@ -1294,6 +1294,11 @@ bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision &
}
void KinematicBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) {
if (p_lock) {
locked_axis |= p_axis;
} else {
locked_axis &= (~p_axis);
}
PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock);
}
@ -1434,6 +1439,10 @@ void KinematicBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody::_direct_state_changed);
ADD_GROUP("Axis Lock", "axis_lock_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_motion_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_motion_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_motion_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z);
@ -1463,6 +1472,7 @@ KinematicBody::~KinematicBody() {
}
}
}
///////////////////////////////////////
Vector3 KinematicCollision::get_position() const {