Paths and Waypoints in Unity

Hi I’m porting a game from 3dGame studio and I am looking for something similar to the concept of “path” in Unity . In 3d game studio a path is a collection of waypoints so the object in motion not only take cares of waypoints but also is “attached” to a path and it can change paths during its movement if required.

Thanks
HtWarrior

If I understand right just animate your object. Set the keyframe as your way points.

afaik there aren’t paths in unity like you’d find in 3dgs. instead you use an empty game object for each waypoint then script what to do on collision.

There is an example of the technique that pete mentioned in On The Edge - Det bedste fra tech verdenen under “Scripting a Game Tutorial”. Perhaps that will help you some.

Thanks, I’ve already read it but what I need is to build a racetrack with more than one “path” ( maybe ten) and then be able to change between “paths” during the race.

HTwarrior

it’s the same thing as paths. there just isn’t an actual path or way point. your way points are your empties. set your track up with strategically placed empties then just like with any path finding, script the ai to change paths. ie i just past empty A1 but there’s a crash blocking A2. cast a ray (or however you decide to handle it) to B2 to see if it’s open. etc. it’ll get a bit complex i imagine but not really different than any path finding ai. guess it depends on the complexity of what you’re trying to do. ok so i’m assuming a lot as i haven’t tried this at home… :wink:

I wouldn’t do individual paths. Instead I would strike lines (“empties”) across the track. Then each car could pick a (biased) random point on the next line and just go there. Then there’s almost an infinite number of paths and 1/10th the number of “empties”.

Also, using a leader/follower system could make a lot of sense. Then you’d only need to figure out 5 paths and the other 5 would follow or base their path on their leader’s. Though, in case a leader crashed you’d have to allow for role reversal I guess.

Just some random thoughts. :wink:

scripting tutorial: if your enemy gets pushed, it still calculates a line towards the next waypoint, its not a fixed line (only its target). I agree it might turn into a problem if there are dynamic obstacles though (e.g a hole in the road the enemy should avoid)

Just to clarify, here’s a (lame) visual aid…

|------x----|
|           |
\--------x--\
 \           \
  |--------x--|

The lines are just guides. The x’s would be the way points but where exactly on the line they are would be chosen by the car’s AI (as it travels around the track) instead of placing specific way points at design time.

Ohh, how 'bout 3 lines (and car “personalities”). Aggressive, normal and timid. More control is nice. You could make the aggressive line shorter (in some areas) for a narrower inside lane, make 'em overlap in some cases, etc.

…the more I think about it the more I want to try it. 8)

cool idea bob! that would make for “intelligent” ai! it also would allow things like drift for your ai. cool!

I just started on a proof-of-concept yesterday and it looks like it’ll take a lot of work/tweaking to get it just right but it could be worth it. Right now I’ve just got two spheres going around an oval track…

My Guide script has 3 references to other guides. The guides each have a Guide script and are setup with box colliders, marked as triggers.

The CarAI script looks at the currentTarget and applies a force to get there. When it gets OnTriggerEnter it exchanges its currentTarget with its guide’s nextTarget (for now, this is always the center lane).

Right now I’m using the guides as normal way points though - I’m not sure how I’d get a random point on a gameObject so that can wait. First I’ll extend the Guide script with a suggestedSpeed variable (mostly for in/out of turns) and then randomize between using the agressive/normal/timid lanes.

I’m guessing I’ll get some car (/sphere) collisions if/when I randomize the paths like that but I think I can deal in the CarAI script. Maybe randomize between hitting back, breaking, accelerating, picking another path or doing nothing…or a combo.

I can’t wait to get half a dozen going on a more interesting track. Might have a demo worth putting up later this week or so. 8)

edit; adding images…



I need to tweak the lower-left guide 'cause they’re hitting the wall there but other than that I’m pretty pleased. The blue ball is a bit faster than the green ball but the green ball can turn sooner/sharper so it almost evens out…which you’d see in the last pic, except the roof beams are in the way. anyway…

well that’s a start - nice job! saw your other post. i’m swamped with work for a couple weeks but maybe after that i can do some model/texture work if you’re still in need.