Need help with AI on spherical world

I currently have a spherical world that uses the common gravityBody and gravityAttractor scripts to keep NPC’s on the surface. I need those NPC’s to find and attack surface structures. Added the A* Pathfinding Project to my game, created a pointgraph since it is a spherical world. The AI scripts included are not a good fit for what I need since they make assumptions about the axis’. So I began to try and write my own simple one based off the example from Arons documentaion at .

So far I have the point graph working great and linking properly. So it’s not a problem. However, when it comes to getting my NPC’s to move around, I’m not having much luck.

First, I can’t actually get them to move very well. Second, when I move them along the path manually, they eventually start doing the limbo.

Any help would be appreciated. AI script is at

Again, thanks for any help.

Well, it seems part of my problem is the scale of the objects in my scene. After scaling things up a bit, I get smooth movement of the npc. It still tries to limbo as it goes along the path and eventually freaks out and starts spinning and flying all over. I’m still losing “up” as the npc travels and I don’t know why.

So I’ve got my npc actually staying up with forward movement now. YAYS!!

But I’m not able to get it facing towards the current waypoint.

Any ideas?


Got rotation working now. Just need to get it smoothed, but it’s looking like that might not happen. all smoothing options make the npc goes crazy when it goes under the sphere.

Edit 3

Solved turning problem.

Quaternion oldRotation = npcTransform.rotation ;
npcTransform.LookAt ( pos, npcTransform.up ) ;
Quaternion newRotation = npcTransform.rotation ;
npcTransform.rotation = Quaternion.Lerp ( oldRotation , newRotation, turnSpeed ) ;

Hi dncwalk99 !

I’m wondering how did you managed to use the pathfinding with a 3D spherical object. On my side the sphere is generated at run time, and I don’t really know how to apply the pathfinding :-/

Hey again dncwalk99 !

Actually, I reached the point from your first post, however I can’t figure out how to fix this limbo and flying effect. How did you solved it ? :frowning:

I have not looked back at that code for a while. I don’t even have access to it at the moment, but I believe I changed the way gravity worked. The common things found for gravity on spherical worlds is a 2 part script. One is a body, and the other is an attractor. I had to do away with that. I ended up using raycasting from the units to a center point on the sphere instead to maintain my “up”. Also changed Unity’s gravity settings. I can’t remember what else I did. Sorry.

Also, you’re using the node graph for this, you’ll want to take advantage of loading/saving/caching the graphs. It makes load times between scenes way faster. And also keep the number of nodes you use to a minimum. One of my problems came down to the number of nodes and the settings for moving to new nodes and such. When the nodes are too close together, the pathfinder will sometimes never complete the path and instead go back to the beginning or fairly close to it. I called this “Roomba-ing”, like the vacuum. The units would go in circles and never achieve path completion.

Guess what I found…

Hope it helps. Pay particular attention to the last 4 methods in the script.

Thank you for tips and code, good stuff, even if it actually going everywhere except to the target point :stuck_out_tongue:
So I guess you left this project ? :slight_smile:

No. It is just delayed for now. Finishing my CS degree is taking priority. As far as finding the target, look at the pointplaneprojection method.

This is really good stuff! Would this work on uneven terrain or does it require a smooth surface? It looks like it would work. Any chance you could share more about how your get the point graph set up on a spherical world? Is it an actual sphere or planes projected onto a sphere? I’m hoping to get it to work on ‘Spherical Terrain’ from the asset store. More code would be awesome! :smile:

Also here is a pretty neat example of how to set up an actual spherical grid. I’m not too savvy with scripting yet but I’m having difficulty seeing how to get it to work with your AI approach as well as terrain. It uses A* calculations but isn’t integrated with actual A* components like yours (i.e. seeker component and AstarPath.cs).

This works on uneven terrain. The pointgraph itself was being generated by another script. And the sphere was a modeled object from C4d. The sphere was multiple objects… a water sphere, an earth polygon, and then a ground sphere. The ground sphere had holes in it that aligned with the rivers/land features.