mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Fix move_and_slide forcing synchronization with physics thread
Co-authored-by: Ricardo Buring <ricardo.buring@gmail.com>
This commit is contained in:
@@ -30,6 +30,10 @@
|
||||
|
||||
#include "character_body_2d.h"
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
#include "servers/extensions/physics_server_2d_extension.h"
|
||||
#endif
|
||||
|
||||
// So, if you pass 45 as limit, avoid numerical precision errors when angle is 45.
|
||||
#define FLOOR_ANGLE_THRESHOLD 0.01
|
||||
|
||||
@@ -416,10 +420,25 @@ void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResu
|
||||
}
|
||||
|
||||
void CharacterBody2D::_set_platform_data(const PhysicsServer2D::MotionResult &p_result) {
|
||||
PhysicsDirectBodyState2D *bs = PhysicsServer2D::get_singleton()->body_get_direct_state(p_result.collider);
|
||||
if (bs == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
platform_rid = p_result.collider;
|
||||
platform_object_id = p_result.collider_id;
|
||||
platform_velocity = p_result.collider_velocity;
|
||||
platform_layer = PhysicsServer2D::get_singleton()->body_get_collision_layer(platform_rid);
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
// Try to accommodate for any physics extensions that have yet to implement `PhysicsDirectBodyState2D::get_collision_layer`.
|
||||
PhysicsDirectBodyState2DExtension *bs_ext = Object::cast_to<PhysicsDirectBodyState2DExtension>(bs);
|
||||
if (bs_ext != nullptr && !GDVIRTUAL_IS_OVERRIDDEN_PTR(bs_ext, _get_collision_layer)) {
|
||||
platform_layer = PhysicsServer2D::get_singleton()->body_get_collision_layer(p_result.collider);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
platform_layer = bs->get_collision_layer();
|
||||
}
|
||||
}
|
||||
|
||||
const Vector2 &CharacterBody2D::get_velocity() const {
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
|
||||
#include "character_body_3d.h"
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
#include "servers/extensions/physics_server_3d_extension.h"
|
||||
#endif
|
||||
|
||||
//so, if you pass 45 as limit, avoid numerical precision errors when angle is 45.
|
||||
#define FLOOR_ANGLE_THRESHOLD 0.01
|
||||
|
||||
@@ -607,11 +611,26 @@ void CharacterBody3D::_set_collision_direction(const PhysicsServer3D::MotionResu
|
||||
}
|
||||
|
||||
void CharacterBody3D::_set_platform_data(const PhysicsServer3D::MotionCollision &p_collision) {
|
||||
PhysicsDirectBodyState3D *bs = PhysicsServer3D::get_singleton()->body_get_direct_state(p_collision.collider);
|
||||
if (bs == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
platform_rid = p_collision.collider;
|
||||
platform_object_id = p_collision.collider_id;
|
||||
platform_velocity = p_collision.collider_velocity;
|
||||
platform_angular_velocity = p_collision.collider_angular_velocity;
|
||||
platform_layer = PhysicsServer3D::get_singleton()->body_get_collision_layer(platform_rid);
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
// Try to accommodate for any physics extensions that have yet to implement `PhysicsDirectBodyState3D::get_collision_layer`.
|
||||
PhysicsDirectBodyState3DExtension *bs_ext = Object::cast_to<PhysicsDirectBodyState3DExtension>(bs);
|
||||
if (bs_ext != nullptr && !GDVIRTUAL_IS_OVERRIDDEN_PTR(bs_ext, _get_collision_layer)) {
|
||||
platform_layer = PhysicsServer3D::get_singleton()->body_get_collision_layer(p_collision.collider);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
platform_layer = bs->get_collision_layer();
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterBody3D::set_safe_margin(real_t p_margin) {
|
||||
|
||||
Reference in New Issue
Block a user