mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Fix move_and_slide forcing synchronization with physics thread
Co-authored-by: Ricardo Buring <ricardo.buring@gmail.com>
This commit is contained in:
parent
de463e0241
commit
6c907c2d37
22 changed files with 226 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue