Can objects track to edges or vertexes?

Hi all,

I’ve been looking at a few Python projects involving pathfinding, and I noticed that some use an underlying mesh to navigate by. Has anyone used this method to create a system that would in essence emulate a motion path by getting an object to follow a meshes vertexes or edges?

Paul

A simple workaround would be to track to an empty and simply move that to follow the position of a vertex or face. Here’s some code I wrote to do a rayCast from an object, then use that to chance the color of the face by changing the vertex colors.


cast = mathutils.Vector((1.0,0.0,0.0))
hitobj,point,normal,face = obj.rayCast(cast,None,100,"",1,0,1)
mat = face.getMaterialIndex()
mesh = hitobj.meshes[0]
ver = []
ver.append(face.v1)
ver.append(face.v2)
ver.append(face.v3)
ver.append(face.v4)
for ind in range(4):
    vertex = mesh.getVertex(mat,ver[ind])
    vertex.color = [0,1,0,1] #Green

Here is the API information for vertex (vertex.XYZ would give you position).
Hereis the API information for polygon (face).

From here, you could simply move the empty to the location of the face or vertex or whatever you want. I’m not sure how you’d be getting the face or vertex information, but this method should work however you get it.

Cool, interesting reading!

Cheers

Paul

You can make your path mesh, using only edges, no faces (the algorithm would become… difficult).

Make a pathfinding algorithm to find out where your player/character/vehicle is looking to go (For example - if the player is detected by a certain raycast, head in that direction <-- incredibly basic), this could be an existing algorithm (A*, Dijkestra, etc) or your own (I use my own because there may be features of the other algorithms that aren’t needed.
(Easiest is if you don’t need pathfinding - just merely a way to follow a set path, from vertex to vertex)

Sorting that out, you’d need to make a script iterate by getting the co-ords of the “next vertex” (This would be determined by a for loop,perhaps using a set-up similar to this:LikeAFor.blend (128 KB)
as there are problems with simple iterations.

Then add the objects global co-ords (the vertex co-ords retrieved will be in local co-ords) to this. In the script, each iteration should:
Player’s X = Player’s X + ((Player’s X - Vertex global coords)/ Num_of_Iterations)
Player’s Y = Player’s Y + ((Player’s Y - Vertex global coords)/ Num_of_Iterations)
Player’s Z = Player’s Z + ((Player’s Z - Vertex global coords)/ Num_of_Iterations)

That will basically smoothly move the object in question to the next vertex.
make the above iteration selective (In an IF statement -

“if player’s X - vertex Global coord’s > Max_Distance and player’s Y - vertex Global coord’s > Max_Distance and player’s Z - vertex Global coord’s > Max_Distance:”

If you still follow, I’ll add the “rest” because it gets a bit “messy”, but otherwise I’ll try and find another way to help, perhaps a small demo…