G’morning.
This is my first post, and I’m hoping for some general guidance.
Lacking much scripting experience, I’m not sure of the best way to approach this (and if I’m being honest, I do hope a prefab exists).
I need to set up a control scheme which involves clicking on a point in the terrain and having my character (3d object) ‘walk’ to it.
Is there any common way to accomplish this?
Any help is appreciated.
Hey there.
Well, that depends on the terrain you’re using and how complicated you want this control to be.
Path finding is one of those tricky things that is pretty hard to accomplish. AngryAnt has a project that addresses this issue:
http://angryant.com/path.html
If your terrain is totally flat, and you just want your character to walk in a straight line, it’s pretty straight forward, but still not that easy.
If your terrain is not flat and has obstacles that the character has to avoid, or holes - where the character can’t go - your best bet is AngryAnt’s creation.
Which is it?..
Attach collider to object, detect mouse down events, then use raycasting to determine the location on the mesh that was clicked, then send the player to that point.
It’s at the “send the player to that point” that things get a little interesting as per the post above. Straight line movement is relatively easy, getting there while avoiding objects requires some sort of pathfinding solution (like AngryAnt’s offering).
Much obliged!
Exactly what I needed as a jumping off point.
Thanks a lot guys.