How can I get the polygon index/position of a mesh the player is on?
Asked Answered
O

4

0

Hi

I have a ground mesh with some path, and I have the player. I want to know which polygon the player is on at that moment.

I do not want to use some kind of abstract grid method because not all my meshes will have grid like structure in the levels.

I am mainly trying to get the polygon index, and the location of that particular polygon.

I know that I need to go through the polygons and see if that polygon location matches the player coords, I just was not able to figure it out in the context of GDscript.

Oria answered 15/2 at 5:50 Comment(0)
I
1

Oria All meshes you import into Godot will be converted to triangular meshes. There's no concept of "polygon" in the mesh data so you can't rely on the mesh topology here. The best approach would still be to construct an abstract representation, regular or not. In general, it's always wise to decouple the functional map data from its visual representation, for myriad of reasons.

Depending on your specific needs, the NavigationPolygon could be useful for this.

Iphigeniah answered 15/2 at 9:42 Comment(0)
O
0

Iphigeniah Thanks for the info. That is a new wrinkle. OK but then how do I go about it if I am trying to construct these grids procedurally? I want to procedurally create these grounds, however in some occasions I will create them in Blender if they are too complex. I am a bit puzzled about how to go about it.

I am guessing that the order of polygons wont be deceiving for to judge, given the object could be on a triangle or on an edge.

Oria answered 15/2 at 16:23 Comment(0)
I
0

Oria It really depends on what exactly you want to create. Is it just irregular quads or polygons with arbitrary number of sides etc... If you want a more specific advice post sketches of typical use cases.

Iphigeniah answered 15/2 at 16:32 Comment(0)
O
0

Iphigeniah The layout will generally be like the image above (polygons attached to eachother on a flat like plane), but the shapes could be primitives like quads, hexagons, pentagons etc but not more than 10 sided probably.

I do not think that I will need to detect collision with those planes, so I am not looking for a collision solution.

Oria answered 15/2 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.