Merge pull request #32274 from raphael10241024/fix_sync_physics_jitter

fix kinematicBody2D jitters when sync_to_physics is turned on
This commit is contained in:
Rémi Verschelde 2019-11-21 08:53:24 +01:00 committed by GitHub
commit 5ef5e6a7e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View file

@ -46,8 +46,6 @@ void CollisionObject2D::_notification(int p_what) {
else else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
last_transform = global_transform;
RID space = get_world_2d()->get_space(); RID space = get_world_2d()->get_space();
if (area) { if (area) {
Physics2DServer::get_singleton()->area_set_space(rid, space); Physics2DServer::get_singleton()->area_set_space(rid, space);
@ -73,19 +71,17 @@ void CollisionObject2D::_notification(int p_what) {
} break; } break;
case NOTIFICATION_TRANSFORM_CHANGED: { case NOTIFICATION_TRANSFORM_CHANGED: {
Transform2D global_transform = get_global_transform(); if (only_update_transform_changes) {
if (only_update_transform_changes && global_transform == last_transform) {
return; return;
} }
Transform2D global_transform = get_global_transform();
if (area) if (area)
Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
else else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
last_transform = global_transform;
} break; } break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {

View file

@ -67,7 +67,6 @@ class CollisionObject2D : public Node2D {
int total_subshapes; int total_subshapes;
Map<uint32_t, ShapeData> shapes; Map<uint32_t, ShapeData> shapes;
Transform2D last_transform;
bool only_update_transform_changes; //this is used for sync physics in KinematicBody bool only_update_transform_changes; //this is used for sync physics in KinematicBody
protected: protected: