Update collision shapes data on tree entered

This is needed because the final startup values for shapes may change between parenting and entering the scene tree. For instance, if the collision shape belongs to a inherited scene.

Fixes #8896.
This commit is contained in:
Pedro J. Estébanez 2018-01-11 21:29:46 +01:00
parent a0de1b8999
commit d7195c18d7
6 changed files with 50 additions and 19 deletions

View file

@ -103,6 +103,19 @@ void CollisionPolygon::_add_to_collision_object(Object *p_obj) {
//co->add_shape(shape,get_transform());
}
void CollisionPolygon::_update_xform_in_parent() {
if (shape_from >= 0 && shape_to >= 0) {
CollisionObject *co = get_parent()->cast_to<CollisionObject>();
if (co) {
for (int i = shape_from; i <= shape_to; i++) {
co->set_shape_transform(i, get_transform());
}
}
}
}
void CollisionPolygon::_update_parent() {
if (!can_update_body)
@ -135,6 +148,10 @@ void CollisionPolygon::_notification(int p_what) {
can_update_body = get_tree()->is_editor_hint();
set_notify_local_transform(!can_update_body);
if (!can_update_body) {
_update_xform_in_parent();
}
//indicator_instance = VisualServer::get_singleton()->instance_create2(indicator,get_world()->get_scenario());
} break;
case NOTIFICATION_EXIT_TREE: {
@ -151,14 +168,8 @@ void CollisionPolygon::_notification(int p_what) {
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (!can_update_body && shape_from >= 0 && shape_to >= 0) {
CollisionObject *co = get_parent()->cast_to<CollisionObject>();
if (co) {
for (int i = shape_from; i <= shape_to; i++) {
co->set_shape_transform(i, get_transform());
}
}
if (!can_update_body) {
_update_xform_in_parent();
}
} break;

View file

@ -50,6 +50,7 @@ protected:
Vector<Point2> polygon;
void _add_to_collision_object(Object *p_obj);
void _update_xform_in_parent();
void _update_parent();
bool can_update_body;