Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / waypoint help

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Dec 2008 17:40 Edited at: 28th Dec 2008 17:43
Hello!

OK, I have 38 waypoints.

What I wan`t to achieve, is to get an object to pick a waypoint and head to it. When reached, it picks a new waypoint and so on.

My waypoints are ordered like this:



The first 3 are not needed.

The waypoint 4 is a limb number, and is also a number that defines a waypoint.

The numbers after the "-" represent the waypoints that the waypoint before the "-" can head to.

When I read in this file, I store the values in arrays. So, waypointx(4,2) will store the x position of the waypoint 32, because the waypoint 4 has 2 options, and option 2 or the waypoint 4 is the waypoint 32.

Firstly, am I doing this correctly?

Secondly, my AI isn`t working at all. If I set the last_waypoint to 17, the next_waypoint to 17 and the selection to 1, I know that the last waypoint visited is 17, and the next 19, because waypointx(17,1) is 19.

When it reaches 19, how can I figure out that I actually reached 19? How can I store the value 19 in the last_waypoint, if the array only returns the position of the waypoint, but not the number?

If I know that, it will help me a lot.

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Dec 2008 00:07
In the DBC challenges, I made a program that you select waypoints on a grid and then the camera will follow those waypoints. Check that out to get some ideas.

Quote: "Secondly, my AI isn`t working at all. If I set the last_waypoint to 17, the next_waypoint to 17 and the selection to 1, I know that the last waypoint visited is 17, and the next 19, because waypointx(17,1) is 19.

When it reaches 19, how can I figure out that I actually reached 19? How can I store the value 19 in the last_waypoint, if the array only returns the position of the waypoint, but not the number?"


Are you randomly going between waypoints or is there an order? You've listed what waypoints are available from each position, but what is the determination of the next one to choose? What's the goal?

Usually there is a progression: 1 to 2 to 3 then maybe back to 1 and alter the course if something happens in between.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Dec 2008 01:20
happen to have a link to that thread? sounds helpful
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Dec 2008 03:24 Edited at: 30th Dec 2008 03:29
It's the grid challenge within the DBC challenge thread. I know of no way to link to a post within a thread.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Dec 2008 19:07
happen to know what page? theres 64 lol i searched through ten and got board hahaha
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Dec 2008 20:05
Phaelax made a Website containing all of the code. Look there.

http://zimnox.com/dbcc/

Quote: "Are you randomly going between waypoints or is there an order? You've listed what waypoints are available from each position, but what is the determination of the next one to choose? What's the goal?"


Well, what I do is write the waypoints (in the code snippet) into a text file, and load them in from there. Each waypoint has a few selections, so what I do first is check how many selections the current waypoint has, then randomly pick a number (if you have five selections, it will pick a number between 1-5).

Once that number is applied, I can get the current waypoint (in this case 17), and add that selection number at the back to get the position of the next waypoint : waypointx(17,2). That will return the X position of the waypoint 21, because selection 2 of the waypoint 17 is 21.

Now, the problem is, I don`t know how to get the actual waypoint number of the next waypoint (21), because it only stores the position of it.

TheComet

Peachy, and the Chaos of the Gems

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Dec 2008 21:52
I might suggest some restructuring.

From the values in your file, I'll assume you have a maximum of 38 waypoints in this case. Trying to keep close to your methods, I might do this:

First, since I know there will be a max of 38 waypoints, I'll use that as a basis for my load array. I'll make the assumption that any waypoint can access another, it just depends on what I put in the file:
dim loadfile(38,38)

The first index for any single waypoint could hold the total number of waypoints that the current waypoint can access:
loadfile(n,0)=number of way points . That means for waypoint 4
loadfile(4,0)=2

To make this happen, I modify the text file to include this count:
4-2,5,32

Since you have commas and dashes in your file, you have to have a parsing mechanism to separate out the numbers. I'll continue as if that's in place (including the count would make it easier to just write and read bytes, words, or longs to the file instead of strings)

The file gets read in:

loadfile(4,0)=2
There are 2 elements to follow this way point:
loadfile(4,1)=5
loadfile(4,2)=32
etc.

At any time, we can look up how many waypoints can be accessed from the current waypoint. To keep things easy, we can have a variable or an array to store the current waypoint. If many objects can use the waypoint system then we will want an array of the object with an index for it's current waypoint and maybe the destination waypoint:
dim objwaypoint(<num of objs>,1)
where
objwaypoint(obj,0)=current waypoint
objwaypoint(obj,1)=destination waypoint


At start or when the destination is reached or within proximity, objwaypoint(num,0) is set to the destination so that becomes the current waypoint. To find the next destination, you mentioned a random selection, we look up the number of possible waypoints in the loadfile() array

waypointindex=rnd(loadfile(objwaypoint(obj,0),0))
destination=loadfile(objwaypoint(obj,0),waypointindex)
objwaypoint(obj,1)=destination


As far as the coordinates, I would have those stored in a separate array as well indexed to the waypoints:

dim wayposition(38,2)
where
wayposition(num,0)=x
wayposition(num,1)=y
wayposition(num,2)=z


Anytime you need to find the current or destination waypoint position for a particular object, just reference the objwaypoint() array:

destx#=wayposition(objwaypoint(obj,1),0)
desty#=wayposition(objwaypoint(obj,1),1)
destz#=wayposition(objwaypoint(obj,1),2)


I think that's about it.

Enjoy your day.

Login to post a reply

Server time is: 2025-06-08 00:10:57
Your offset time is: 2025-06-08 00:10:57