Mesh Go, Stop, Rotate, Go!

Hello everyone,

I’m working on game character AI for movement. Here is what the mesh is supposed to do:

  1. Move for a certain amount of time along X/Z axes (let’s say 3 seconds).
  2. After 3 seconds, stop, rotate along the Y axis for a random value (Math.PI, Math.PI/2, Math.PI/4, etc.).
  3. After rotation, travel along LOCAL X/Z axes for 3 seconds.
  4. Repeat on loop.

Here’s the PG I created that incorporates some of these elements:

I’m obviously missing the timed stops, and the movement along updated local axes :thinking:

If you want the local forward direction, you can use the matrix of the sphere mesh:

This is exactly right, thank you @Raggar! :smiley: :+1:

I’ll need some time to study and fully understand this code, but the mesh is moving correctly.

There’s one other element that I can’t seem to figure out. Any suggestions for how to get sphere2 (the grey one) to follow the moving sphere around the map?

Based on the grey sphere’s speed, it will be able to follow and eventually collide with the textured sphere, or it will just continue to try to move to the textured sphere’s current XYZ position if its speed is too low.

Thanks again for the help!

That depends on how you want it to behave. There are multiply ways of achieving that.
You can use the direction between the two meshes, you can interpolate between the positions, you can rotate the grey sphere toward the other one and use the local forward axis like above. It’s a matter of what’s needed in the end. This is probably the easiest way:

Once again, you accomplished in a few minutes what I’ve been stuck on for days :joy: :+1:

Being new to programming, I have about a dozen other questions about why this code works, but I’ll study it and try to figure it out over time.

Thanks again!