Making entity follow path correctly

im having an issue getting my character to follow the path correctly. it deviates from the path slightly but i want my character to stay on the path 100% of the time because im making a tile based game. and im fairly new to programming with unity.

Do you have the simple smooth modifier on? I’m making a tile based game too, and the simple smooth modifier makes the character deviate from the path to avoid jerky looking movements -especially when the character makes a rapid series of diagonal turns.

no i don’t have the simple smooth modifier on i am using almost the exact same script from the getting started tutorial i ended up just setting my way point distance down to the lowest i could set it which weirdly is.02 it still deviates from the path but it isn’t visually noticeable.

Hi

All included movement scripts will deviate from the path slightly to avoid unnatural movement. However in some games you really want it to follow the path exactly.
You can use this script for that which will interpolate along the path to follow it exactly: http://pastebin.com/DvjRLQLV

[EDIT] In newer versions of the package you can use the included AILerp movement script.

1 Like

thank you that really helped and works great.

1 Like

Sorry to “necro” this post, I tried your script Aron but my characters move very choppy. I do have a rigid body attached to it. But I have no clue what else it may be.

Characters also have inconsistent movement speed between nodes. I’m on Unity 5.1.1f

Hi

If you want them to follow the path “exactly” (as the author to this post wants) then it will be a bit choppy. You can add a Simple Smooth Modifier if you want to smoothen it a bit.
It will not use the rigidbody at all, it will just linearly interpolate along the path.

That script should take care of speed normalization so it’s odd that you are seeing different movement speeds between nodes.

Before I used your lib I had a simple node system in which I just made the character move with the transform.forward and rotated when i got within a proximity of the goal to the next one. I think Ill rewrite the linear interpolation and do that. Won’t work well at higher speeds but my characters move kinda slow.

The current AIPath class makes my characters look like they are on ice so can’t use that either.

Thanks for the reply.

Hi

I think the AIPath class should be able to do what you want, but it might need some tweaking to the parameters. Check the example scenes and see how they are configured.

I tried the settings in the example. I’m trying to make them move slowly but anything below speed 5 won’t make them budge. I’m not entirely getting how the AIPath works. I did read the documentation but I simply can not get a satisfying result.

Edit:

I’m on a 3 message limit so @ below:

rigidbody was the culprit. Character controller works wonderfully well. Thanks.

Hi

Try using a CharacterController instead of a rigidbody. When a rigidbody is used it will apply a force to it instead of just setting the velocity as with the CharacterController. Applying a force will usually make it look more like it is on ice.