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 / A.I. problem with spaceship

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Feb 2008 20:11
Greetings!

I have a problem with steering my ship by computer. Here is the source for an example I quickly made:



I want the red sphere to collect the plain objects. But it should only collect the ones nearest to it. The variables x4# and y4# should be incremented and decremented by 0.3.

Thanks, TheComet

Oooooops!!! I accidentally formated drive c.
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 9th Feb 2008 23:23
use a function to calculate distance in 3d space, then steer the spaceship in that direction. easy
eventually you'll need a function to calculate if the space ship can travel the distance in the time given (but only if is Z speed is constant). if it can't, then let it ignore that plain.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Feb 2008 00:19
@Link
If the ship gives up on the closest plain then it wont go anywhere

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Feb 2008 03:45
Sounds kinda like your trying to set up a way point system with randomly placed points (objects in this case). One way might be to have an invisible sphere around your ship. Use OBJECT HIT to detect when the sphere is hitting an object. The first object that it reads you can consider to be the closest and first object to point towards and etc.

If there is no collision, scale the sphere outward until it hits a plain then point the ship in that direction. As you scale the outside sphere, you will have to make a mesh out of it and then change the mesh of the outside object to the new mesh - otherwise the collision won't work.



Enjoy your day.
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 10th Feb 2008 12:59
Quote: "@Link
If the ship gives up on the closest plain then it wont go anywhere"


no I mean, ignore the closest plain and go to the seccond closest

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 10th Feb 2008 20:57
good Idea, Latch. I thought more in this direction:



But that code doesn`t work. Can someone go over it?

Thanks, TheComet

Oooooops!!! I accidentally formated drive c.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Feb 2008 00:18
The problem is with the comparison. A position can be positive or negative. If a plain is at x=-4 and another one is at x=2 and your ship is at x=0, your expression if shipx > x, is going to think x=-4 is closer when it's actually farther away.

Another sugestion, you can find the distance between two points with
sqrt((x1-x)^2+(y1-y)^2+(z1-z)^2)
Before play even starts:
If you place all of your plains randomly around, then from where ever your space ship starts, run through all 30 plains, find the one that is closest to the ship, record those coordinates in an array sequentially (maybe dim plainpos(30,2) where plainpos(num,0)=x plainpos(num,1)=y plainpos(num,2)=z)

Then starting from that plain position, run through the remaining 29 and find the closet to that position and record it in the next space in the array. Repeat this for the remaing 28, 27 etc.

When your game begins, just loop through the array with each position recorded that the ship will move to in order. It should be very fast and remove the calculation of position from the main game loop.

Another option is to use a path finding routine (the one above is one but a little clunky). Instead of finding the way to go that is open, you would find the way to go where an object is located. A while ago a user named Alien 001 made a very fast 2d path finder. You may be able to modify it for 3d.

http://forum.thegamecreators.com/?m=forum_view&t=115845&b=6

Also a user named luke810, put together an A* (a star) path finding routine for DBC that you may be able to adapt to your purposes.

http://forum.thegamecreators.com/?m=forum_view&t=112682&b=10

Enjoy your day.
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 12th Feb 2008 01:09
@Link: I'm confused. Or drunk. Nevertheless, if it can't reach the closest plain within the time limit, why would it be able to reach a further away one in the same time period?

"A West Texas girl, just like me"
-Bush

Login to post a reply

Server time is: 2025-06-04 01:56:22
Your offset time is: 2025-06-04 01:56:22