Get node rotation?

Hey there,

I use layared grid graph. I’m spawning my own grid visualization during runtime, for which I use graph node positions. Although, since I have multiple layers and thus some slope surfaces to connect them, I can’t rotate my visual nodes accordingly to the graph nodes, as there is no rotation property/field in GraphNode class.

Is there any way to obtain this info? Since the grid graph mesh contains nodes that are rotated along with my slopped surfaces, I reckon there must be a way to read this info from each node, I just can’t figure where to look.

Thank you

Adam

Hi

Do you mean the slope of the terrain at that point?
This is used when generating the graph, however since it is not used by any pathfinding scripts it is not saved (to reduce memory usage). You can get the slope and store it in a custom script by using Physics.Raycast.

As a quick demonstration, I include screenshots:

First one shows how is the grid graph set up. You can clearly see that the nodes are slopped along the surface.

To visualize grid in-game, I use my custom code that spawns my own node prefabs onto selected grid graph nodes positions (then combines them into one mesh to save draw-calls). As you can see in the second screen, nodes supposed to represent the slopped surface are not rotated accordingly, that’s why I was trying to get the original gridgraph node rotation.

So there is no other way than raycasting, corrent? That’s frankly the option I was trying to avoid. But if there is no other way, I’ll try that. Although I’m not quite sure how would the raycast give me the rotation info in this case.

Hi

The vertices for the mesh visualization is calculated based on the positions of adjacent nodes. Thus it does not represent the slope of the terrain below it. An extreme example is a stair, the ground at all positions is flat, but the visualization will have a slope since the adjacent nodes have different positions.

You can find the code that the package uses internally in GridGraph.CreateNavmeshSurfaceVisualization