mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-04-11 06:12:38 +02:00
Fix wrong collision reported on move_and_collide
This commit is contained in:
parent
2b3f3fdc9d
commit
75a882d02e
@ -994,7 +994,10 @@ void RigidBody2D::_reload_physics_characteristics() {
|
|||||||
Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) {
|
Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) {
|
||||||
Collision col;
|
Collision col;
|
||||||
|
|
||||||
if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) {
|
bool collided = move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only);
|
||||||
|
|
||||||
|
// Don't report collision when the whole motion is done.
|
||||||
|
if (collided && col.collision_safe_fraction < 1) {
|
||||||
// Create a new instance when the cached reference is invalid or still in use in script.
|
// Create a new instance when the cached reference is invalid or still in use in script.
|
||||||
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
|
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
|
||||||
motion_cache.instance();
|
motion_cache.instance();
|
||||||
@ -1104,6 +1107,7 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_
|
|||||||
r_collision.travel = result.motion;
|
r_collision.travel = result.motion;
|
||||||
r_collision.remainder = result.remainder;
|
r_collision.remainder = result.remainder;
|
||||||
r_collision.local_shape = result.collision_local_shape;
|
r_collision.local_shape = result.collision_local_shape;
|
||||||
|
r_collision.collision_safe_fraction = result.collision_safe_fraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p_test_only) {
|
if (!p_test_only) {
|
||||||
|
@ -282,6 +282,7 @@ public:
|
|||||||
Vector2 remainder;
|
Vector2 remainder;
|
||||||
Vector2 travel;
|
Vector2 travel;
|
||||||
int local_shape;
|
int local_shape;
|
||||||
|
real_t collision_safe_fraction;
|
||||||
|
|
||||||
real_t get_angle(const Vector2 &p_up_direction) const {
|
real_t get_angle(const Vector2 &p_up_direction) const {
|
||||||
return Math::acos(normal.dot(p_up_direction));
|
return Math::acos(normal.dot(p_up_direction));
|
||||||
|
@ -965,7 +965,11 @@ void RigidBody::_reload_physics_characteristics() {
|
|||||||
|
|
||||||
Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) {
|
Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) {
|
||||||
Collision col;
|
Collision col;
|
||||||
if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) {
|
|
||||||
|
bool collided = move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only);
|
||||||
|
|
||||||
|
// Don't report collision when the whole motion is done.
|
||||||
|
if (collided && col.collision_safe_fraction < 1) {
|
||||||
// Create a new instance when the cached reference is invalid or still in use in script.
|
// Create a new instance when the cached reference is invalid or still in use in script.
|
||||||
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
|
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
|
||||||
motion_cache.instance();
|
motion_cache.instance();
|
||||||
@ -1038,6 +1042,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in
|
|||||||
r_collision.travel = result.motion;
|
r_collision.travel = result.motion;
|
||||||
r_collision.remainder = result.remainder;
|
r_collision.remainder = result.remainder;
|
||||||
r_collision.local_shape = result.collision_local_shape;
|
r_collision.local_shape = result.collision_local_shape;
|
||||||
|
r_collision.collision_safe_fraction = result.collision_safe_fraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -280,6 +280,7 @@ public:
|
|||||||
Vector3 remainder;
|
Vector3 remainder;
|
||||||
Vector3 travel;
|
Vector3 travel;
|
||||||
int local_shape;
|
int local_shape;
|
||||||
|
real_t collision_safe_fraction;
|
||||||
|
|
||||||
real_t get_angle(const Vector3 &p_up_direction) const {
|
real_t get_angle(const Vector3 &p_up_direction) const {
|
||||||
return Math::acos(normal.dot(p_up_direction));
|
return Math::acos(normal.dot(p_up_direction));
|
||||||
|
Loading…
Reference in New Issue
Block a user