Second Life PathFinding Tutorial

I’ve wanted to take time to play with the new Pathfinding feature now in alpha testing on the ADITI grid, also known as the Preview Grid. I took the time this weekend. I learned a few things. As you may imagine the documentation is incomplete at this stage. Not much point in writing lots of information that may change.

My First Pathfinding Bot

I’ll explain some of the problems I ran into with Pathfinding and then get into the script and how I fixed the problems. This is not a beginning tutorial for scripting. I am assuming you know about basic scripting with the Linden Scripting Language.

Simple

Writing Pathfinding scripts is way way simple compared to what was previously needed to create similar behavior. My first try was to create a follower. I have a Serge inspired character I made for OSGrid and decided to use that. My little bot is made from two prims and a sculpty. Because of the sculpties work I have to scale it to make it look right. That wacks the bounding box, which I was not over concerned with when I made it. Someday I’ll need to redo it in mesh.

The sculpty gave me my first challenge.  I needed to rebuild my bot here in SL. I rezzed the spheres I needed and put him together. Then wrote the script and tried him out. He promptly fell over on his side… 

Making a sphere and 2 copies

It took some experimenting, but I learned the problem was in my root prim at the base of my bot. Going through and setting all the parts to zero rotations solved the falling over problem. Later, when I made a completely new copy of my bot I made 3 spheres and set the first sphere to 0, 0, 0 rotation. Then I copied the sphere twice by Shift-dragging the Z-axis. That avoided the flopping over problem.

Direction

My bot sort of has a face. So, I needed to face him forward when walking… rolling, whatever. With the flopping problem I learned about rotation. One of the things I learned is the object one turns into a pathfinding character uses the positive X axis-direction as the front.

This means if one rezzes a cube the east face is the front side and the face the bot will have forward when moving.

Oops! He Floats in the air.

Floating

In my case I want the little guy to appear to roll along the ground. So, of course my guy floats a meter or so above the ground. It is that bounding box thing with the sculpty.

All the cubes in the Path Test regions hug the ground. So, I’m off to the wiki and JIRA to read up on what I need to do. The JIRA explains what things are not working. The wiki tells us what should be happening. See the wiki here: Pathfinding LSL functions for a good index to Second Life’s Pathfinding functions. For the JIRA see the Pathfinding External Bugs project.

To make any pathfinding object one must turn it into a character. You can convert a a prim, sculpty, mesh or a link set made of any combination. The conversion changes your object into one using the Land Impact cost system. So, pay attention to what your LI is costing as these objects will count against prim limits.

Building my bot with a sculpty

The llCreateCharacter() function is used to convert objects into characters. This is done to alert the Havok physics system that this item will need to use the Pathfinding system. I suspect Havok is why the conversion uses the term character. I might read the Havok manual someday…

In the llCreateCharacter() function are two related attributes; CHARACTER_RADIUS and CHARACTER_LENGTH. These control the size of the convex hull used for the physics (collisions) of Pathfinding objects, which are called characters. These are the attributes I need to get my little guy down on the ground.

The wiki tells me that CHARACTER_LENGTH must be at least (CHARACTER_RADIUS x 2) + 0.1. It also tells me the minimum radius is 0.1. It isn’t. It is 0.125. Anything smaller gives a script error and the message that 0.125 is minimum. So, I changed the wiki.

This means the minimum CHARACTER_LENGTH is 0.35.

The minimums just get my little guy on the ground. If they hadn’t I would have needed to go back to Blender and do something about the bounding box.

Following

For now I want my guy to follow me around. I think this will be an easy thing to do and I have written follow scripts… well modified existing ones… for some monsters in SL. It will give me a comparison.

The Pathfinding feature I need is:  llPursuekey target, list options ). There is an example script on the wiki page and I just used it. The options are placed in a list. There are only 4, so it is easy to learn and test.

You do not get to set the character’s speed in the llPursue() function. That gets set with you create the character with llCreateCharacter(). You do get to set the target location in relation to what or whoever the object is to pursue. The location is an X, Y, Z position that is added to the location of the pursue target. Zero values will lead to a collision. With the collision events you can program behaviors for those events.

A follower is really easy to set up.

Events

The Pathfinding functions have an event: path_update. Using this event trigger you can test for 11 events returned by the system.

  1. PU_SLOWDOWN_DISTANCE_REACHED
  2. PU_GOAL_REACHED
  3. PU_FAILURE_INVALID_START
  4. PU_FAILURE_INVALID_GOAL
  5. PU_FAILURE_UNREACHABLE
  6. PU_FAILURE_TARGET_GONE
  7. PU_FAILURE_NO_VALID_DESTINATION
  8. PU_EVADE_HIDDEN
  9. PU_EVADE_SPOTTED
  10. PU_FAILURE_NO_NAVMESH
  11. PU_FAILURE_OTHER

 

The weekend of Feb 3 Falcon was going to update the server code with the Collision Detection enabled Pathfinding. Update: 3/17 – collision is rolling out and should be on the ADITI grid now.

Other events seem to work too. I tried moving_start( ) and moving_end( ). They both work.

You can find the possible events to use here: LSL Event ID’s.

My First Pathfinding Bot

Rotation

I wanted to be able to have my guy lean into acceleration and bank through turns. The moving start event will let me handle start up. The path_update slow down distance will help with stopping. But, I don’t see a way to handle turns. I can check rotations and determine whether the bot is turning. But, that is going to be lagging behind the actions. It probably won’t look good. But, I may be missing something. There is a lot I do not know about LSL.

As best I can tell llSetRot() does not work with a Pathfinding object. I know Pathfinding is updating the rotation on the Z-axis. But, I don’t see why it would over ride the X & Y axies. Whatever the case I can not change the orientation of my bot.

llSleep

This function pauses a script. It does not affect Pathfinding.

Prim Attributes

An aspect of Pathfinding is that it changes the attributes of an object. Just as particle settings and rotation are prim attributes. One can remove the script that sets the attributes. A script that sets up a Pathfinding behavior can be removed and the behavior continues.

But, a script has to be present to catch ‘events.’

2 thoughts on “Second Life PathFinding Tutorial

  1. Pingback: Pathfinding parte 2. Scriptare un personaggio in LSL. « VIRTUAL WORLDS MAGAZINE

  2. Pingback: Pathfinding parte 2. Scriptare un personaggio in LSL. | VIRTUAL WORLDS MAGAZINE

Leave a Reply

Your email address will not be published. Required fields are marked *