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 / Complex Enemy AI Question

Author
Message
Trial
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location:
Posted: 22nd Nov 2003 22:05
I want to have multiple enemies that will animate and attack me when i get to close. I have written a very long function that worked for one enemy, but when i put two in, they did not work right because the variable's i'm using (for detecting my presence, for changing animations, etc.) are the same for both enemies. I know i could just type out individual functions for each enemy, but i plan to have 10's, or 100's, of enemies in the game at once (their low graphic models). How would i right a function that used individual variables for each enemy automatically? The code is the Function for controlling my AI (sorry if it's low quality...I'm new). To make sure its clear, this code works perfect for 1 enemy.
Blazer
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: United States
Posted: 22nd Nov 2003 23:31 Edited at: 22nd Nov 2003 23:32
I see your enemy is the 3rd one, so you would do this on all the coded where you have to imput object # 3 (or around the whole code)

old one:dist#=(sqrt((object position x(x#)-object position x(3))^2+(object position y(x#)-object position y(3))^2+(object position z(x#)-object position z(3))^2))-10

new one:
for i=3 to 103
dist#=(sqrt((object position x(x#)-object position x(i))^2+(object position y(x#)-object position y(i))^2+(object position z(x#)-object position z(i))^2))-10
next i

this will make objects 3-103 do the same thing, hope that helps

As I walk through the vally of the shadow of death, I will fear no evil.
- Psalms 23:4
Trial
21
Years of Service
User Offline
Joined: 28th Aug 2003
Location:
Posted: 22nd Nov 2003 23:37
sorry, what i wrote wasn't very clear. x# is the enemy, object 3 is the hero player object.
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 23rd Nov 2003 09:57
just incase u havnt got it just make it:

quote:
"new one:
for i= C + X# to (C + 100) + X#
dist#=(sqrt((object position x(x#)-object position x(i))^2+(object position y(x#)-object position y(i))^2+(object position z(x#)-object position z(i))^2))-10
next i
"

note: also seeing as X# is a real number all u need is an integer? or am i missing somthing?
and "C" is the inital enemy object number so if u wanted the enemys to be numbered from 100 to 200 u would have C as 100

p.s. i know this post might be not needed but im just trying to get my spot in society
Darkwing
21
Years of Service
User Offline
Joined: 20th Nov 2003
Location: New Jersey
Posted: 23rd Nov 2003 18:03
this might help, with the variables you use for one enemy, make an array of all of them. "dim enemydetect#(N)", for example

that way you can either pass the array into the funcion (for each enemy) or if thats not possible use a for...next loop and go into the function with each pass. hope i help
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 23rd Nov 2003 22:45
yes use an array, send to the function what enemy # you are using. and use var(endemy#) = blah, instead of var = blah. do you get what i mean?

=<=Pudgie Wars=>=
Game engine: 15% = Models: 25% = Textures: 1% = Sounds/Music: 0%

Login to post a reply

Server time is: 2025-05-21 16:19:47
Your offset time is: 2025-05-21 16:19:47