Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | VincePrinceKing | |
Old Version | Published before Godot 3 was released. |
I tried getting the intersect_point() to work in a 2d world, but i cant make it get me any results. I’m using it in a node2d player scene and am checking for node2d scenes with static or rigid bodys attatched to. I couldnt find any examples how to use it, so i’m asking here.
I tried to make it work on the (0.0) coordinate first, but coudln’t make it return anything.
What am i doing wrong?
Also how to check a position relative to my player scene?
Array intersect_point ( Vector2 point, int max_results=32, Array exclude=Array(), int layer_mask=2147483647, int type_mask=15 )
func _fixed_process(delta):
var space_state = get_world().get_direct_space_state(self.get_world().get_space())
var result = space_state.intersect_point( Vector2(0,0))
if (not result.empty()):
print("Hit at point: ",result.position)
The doc says intersect_point
will check if a point is inside a shape. Which kind of collider are you trying to detect?
Zylann | 2016-11-07 13:45
You are getting the 3D direct space state, but are then using a 2D method called “intersect_point”, maybe its related?
Bojidar Marinov | 2016-11-07 13:52
- What exactly is a shape in godot? Does a simple image already have a shape? Like a recangle of its measures? I thought it checked for collision shapes only. So i tried to test with a Staticbody2d with a rectangle CollisonShape2d.
- so “get_world()” is always 3d and i have to use “get_world_2d().get_direct_space_state” instead?
VincePrinceKing | 2016-11-07 14:25
- Well, collision shapes are the thing you need, sprites don’t have a “shape” at all. To be fair, a collision shape on its own won’t be enough, it would need a collisionbody as well.
- Yeah, that’s correct
Bojidar Marinov | 2016-11-07 14:27