Add raycast options to hit when starting inside / hit back faces
Makes the results consistent for all shape types with options to set the desired behavior.
This commit is contained in:
parent
3668312e78
commit
c3ae7ddedd
22 changed files with 164 additions and 55 deletions
|
|
@ -153,6 +153,22 @@ bool GodotPhysicsDirectSpaceState2D::intersect_ray(const RayParameters &p_parame
|
|||
|
||||
Vector2 shape_point, shape_normal;
|
||||
|
||||
if (shape->contains_point(local_from)) {
|
||||
if (p_parameters.hit_from_inside) {
|
||||
// Hit shape at starting point.
|
||||
min_d = 0;
|
||||
res_point = local_from;
|
||||
res_normal = Vector2();
|
||||
res_shape = shape_idx;
|
||||
res_obj = col_obj;
|
||||
collided = true;
|
||||
break;
|
||||
} else {
|
||||
// Ignore shape when starting inside.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (shape->intersect_segment(local_from, local_to, shape_point, shape_normal)) {
|
||||
Transform2D xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
|
||||
shape_point = xform.xform(shape_point);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue