Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

Waypoint pathfinding

Started by bazeragi Apr 23, 2009 at 7:51 AM 3 replies 2.1k views
Original Post
bazeragi
bazeragi
Hi, i am making a 3D motorbike racing game i want to put some very simple AI into it so the other bike just follows a set path, i have got waypoints set all round the track using vector2 but i carnt work out a way to make the bike move to each waypoint. Can anyone tell me how i might be able to do it?
Captain P
Captain P
I don't think you're going to need pathfinding here, assuming that the tracks are more or less linear.

You could simply link waypoints to each other. Once a bike arrives at a certain waypoint, he checks what waypoint it is pointing to. To add a little variety, you can make waypoints point to multiple other waypoints, so a bike can pick one of them at random.
bazeragi
bazeragi
yes thats the sort of thing im after it only has to be very simple but im not sure how to actually work out how to move the bike to the next waypoint like get it from its start position to move along to the next waypoint.
DaveMS
DaveMS
If you position the waypoints so that the path from one to the next is a straight line, it's a lot easier.

You need to check when the bike has reached a waypoint, find the position of the next waypoint and tell the bike to move towards that position. Once it reaches that waypoint, get the position of the next and tell the bike to move to that position, and so on...

If the bike can only traverse the waypoints in one way, you could just create a container of waypoints (std::vector maybe?), and add the waypoints to the vector in the order you want them traversed.

Once the check returns true that the bike has reached the current waypoint, find the next in the vector and travel to it's position. When you get to the end of the vector, set the next waypoint to the beginning again if you want to loop through the waypoints.

edit: and to travel to a waypoint, you need to find the line between your bike and the waypoint. The rest i'll leave to you :)

bazeragi
bazeragi
ok thanks for the help

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.