diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/path_2d.cpp | 20 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 12 |
2 files changed, 15 insertions, 17 deletions
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 55c055e34f..e1c7331393 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -117,29 +117,27 @@ void PathFollow2D::_update_transform() { Vector2 pos = c->interpolate_baked(o, cubic); - Vector2 offset = Vector2(h_offset, v_offset); - - Transform2D t = get_transform(); - t.set_origin(pos); + Vector2 displacement_offset = Vector2(h_offset, v_offset); if (rotate) { Vector2 t_prev = (pos - c->interpolate_baked(o - delta_offset, cubic)).normalized(); - Vector2 t_cur = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized(); + Vector2 t_next = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized(); - float dot = t_prev.dot(t_cur); - float angle = Math::acos(CLAMP(dot, -1, 1)); + float angle = t_prev.angle_to(t_next); - t.rotate(angle); + set_rotation(get_rotation() + angle); - t.translate(offset); + Vector2 n = t_next; + Vector2 t = -n.tangent(); + pos += n * h_offset + t * v_offset; } else { - t.set_origin(t.get_origin() + offset); + pos += displacement_offset; } - set_transform(t); + set_position(pos); } void PathFollow2D::_notification(int p_what) { diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 6ab20efdcc..a809023083 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -120,11 +120,11 @@ void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { if (!is_inside_tree()) return; - if (Object::cast_to<PhysicsBody2D>(get_parent())) { + if (Object::cast_to<CollisionObject2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); } } @@ -144,11 +144,11 @@ void RayCast2D::_notification(int p_what) { else set_physics_process(false); - if (Object::cast_to<PhysicsBody2D>(get_parent())) { + if (Object::cast_to<CollisionObject2D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<PhysicsBody2D>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid()); } } break; case NOTIFICATION_EXIT_TREE: { |