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.

Newcomers DBPro Corner / Programming Simple AI Routines

Author
Message
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 02:02 Edited at: 27th Apr 2003 02:06
I'm currently designing a small 2D space shooter game. Much like Star Control 2, you move your space ship around in that fashion, fighting 1v1 with another spaceship..

I'm having trouble figuring out how to make the enemy ship know whether or not to turn left or turn right.. If I was in the upper right area of the screen and they were in the lower left area of the screen, and they were facing up, they'd want to turn a little to the right so they could face me and shoot at me..

I was searching for "facing" commands... something like, turn right until your facing him, etc.. But I cant find any. And I dont know how to program the AI to know which direction to turn...

Does anyone have a small example of how something like that works?

& Thanks everyone for all your help in the past! I hope that I'll return the favor some day..


EDIT : I messed up on the explanation
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 02:05
I'm not sure if you've played Star Control or not.. But if you haven't.. Let me explain the game detail a little bit... As Brief as possible..

Its a top down space shooter, you control your ship like you do in asteroids. only you aren't shooting asteroids, you are against another ship that is trying to destroy you.. The other ship flies like you do, their ship must be facing you to shoot at you.. So the AI has to know which way to turn, etc.

Hope that clears things up..
koolaid
21
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 27th Apr 2003 14:27
rotate it to a certain degree so its facing you im not a 2d person? but in 3d i would just rotate the object and make it shoot.
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 27th Apr 2003 17:59
You need a function to find the angle between the two sprites.

Atanfull is the command you need to get the angle between the two sprites.
k0shi
21
Years of Service
User Offline
Joined: 30th Dec 2002
Location: Cyberspace
Posted: 28th Apr 2003 04:35
ive never played star control so im not sure if ur asking for rotation or sliding to the left or right.

for sliding:
if player1_x<badguy_x then badguy_x=badguy_x-1
if player1_x>badguy_x then badguy_x=badguy_x+1

for rotating:
rotating is the same thing except instead of minus 1 from badguy_x, u would rotate it to the left and instead of plus 1 to badguy_x u would rotate it to the right. i dont know any rotating commands but i heard DarkBasicPro has one.

...
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 28th Apr 2003 15:17
Thanks everyone for your helpful comments. I have finally made the AI rotate when it has to. Including chase your ship, and fire at it is aimed at you.. I think it's pretty cool so far! I can't wait until I'm done with it..

Thanks everybody!

PS: I am using a function to find the angle it needs to be at to point at your ship. It then finds out how many degrees it needs to turn to point at your ship, and puts in effort to turn at its maximum turning speed. Depending on which ship it is will give different results. I will post a code snippet if ya want.

Again thanks!
Furiousuk
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 28th Apr 2003 15:27
Be sure to let us know when you have a beta version or a final version so we can check out all your hard work.

The Fury
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 28th Apr 2003 17:29
i usually make four to six points around the enemy ship so there is a point in front, behind, to the left, to the right, and at the top and bottom of the ship then i compare the distance between the points around the enemy ship and it's target...like if the top is closer to the target than the bottom then it pitches the ship up, if the left is closer than the right then the ship turns left, if the front is closer than the back it speeds up and fires. i have a function to do this just not with me right now, if you wan't i will post it later when i have the time.

Anyone Can Destroy...But Few Can Create...
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 29th Apr 2003 15:21 Edited at: 29th Apr 2003 15:24
@ Furious UK : thanks! I appreciate your support. I'll definitely post my game on the forums here when it reaches it's beta stage. I still have a few things to work out with its AI, and organizing the code so it can be read well..

@ Game_Creator : Since my game is 2D, I'm using 4 points, and it works just about like yours, and also use a distance function to find out how fast it needs to go. I'm still working out a few things here and there. It is kinda hard to make the enemy ship fly away once it gets too close, so it crashes into u alot. Any Ideas?
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 29th Apr 2003 15:33
In 2D game programming: If you'd like to know how to have an enemy find the angle it needs to be facing the player go here : http://www.darkbasicpro.com/apollo/view.php?t=9524&b=4



Thanks to "Easily Confused" for providing the code!!

Login to post a reply

Server time is: 2024-11-24 12:57:30
Your offset time is: 2024-11-24 12:57:30