Find the positions that a collision shape is covering

Godot Version

4.6.3

Question

So what I’m trying to do is to instantiate a node that acts as a one shot, but only able to appear on certain positions that the collision shape is covering. So how do I find the positions that the collision shape is covering? Or at least the range of the position.

Put tiny collision shapes at the positions and check for intersection with the main shape. Alternatively you can use PhysicsDirectSpaceState3D::intersect_point()

I forgot to mention that I’m working on the 2d side, and thanks for the help, but I found my own way before your reply, it goes something like this :

var min_x_pos = area_pos.x - (shape_size.x / 2)
var max_x_pos = area_pos.x + (shape_size.x / 2)
var min_y_pos = area_pos.y + (shape_size.y / 2)
var max_y_pos = area_pos.y - (shape_size.y / 2)

There’s equivalent 2d functionality.

You also forgot to mention your shape is a rectangle, which simplifies things. However your solution won’t work for any other type of shape.

If you want to do it “manually”, you can implement is more elegantly by getting shape’s rectangle and useing Rect2::has_point():

position_is_inside = Rect2(area_pos + shape_size / 2.0, shape_size).has_point(some_position)