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 Professional Discussion / rotation of several enemies

Author
Message
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 1st Dec 2010 12:45
i am loading the x model and the textures before the main do-loop.



I have created a function enemies() which is called in the main do loop



I want the objects 500 to 530 to be placed on my map randomly. Also i want the model only to rotate 180 degrees then go back to 0 and keeps doing that. As if they were looking around!!

I dont know where to begin, any help would be great!!
MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 1st Dec 2010 13:02
i also want them to detect the player which ID is 2.

so if within a certain radius they detect the player stop rotating and start firing!
TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 1st Dec 2010 13:10 Edited at: 1st Dec 2010 13:31
Argh! My message got deleted when I pressed Ctrl+something, then I re-wrote everything and it got deleted again! So here we go, the third time:
You don't have to reload the model and texture all over again, you can just use one time:

Outside of DO-LOOP


And what comes to rotation, I don't think for-next is the best/fastest solution so I hope other members can help you with that, but you could try:
In DO-LOOP(or in your function):



And direction changing maybe like this:
Just call these outside of the DO-LOOP:
enemyangle=90
turndir=1
Then DO-LOOP:


Alternative to turning would be to use for example curvevalue function for smooth turning.
I'd recommend DarkAI if you have spare money, it handles the enemy model quite well(walking direction, path finding, etc.).

There is good way to find out if the player is in view range, I explain this but I can't give any good code atm:
1.Place a(hidden) cube object at the enemy's head.
2.Point the cube object to player all the time
3.Check difference between: A: Enemy direction B: Cube object direction
4.If it is smaller than view range(for example 30 degrees) then execute "player detected stuff".
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Dec 2010 13:54 Edited at: 1st Dec 2010 13:56
The system you are currently using has massive flaws however. You limit yourself to only 30 enemies by hardcoding the id's of each object. A better way to achieve a more optimized and dynamic system would be to create a UDT array containing the object id, position, rotation etc and dynamically assigning object id's when you create a unit.

For example, in my RTS, i have a type similar to this: -



To create a unit I'd use a function such as this:-



MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 1st Dec 2010 15:52
i have dark ai but not very confident using new commands as im still getting used to dbpro alone!

if you ever have any new ideas id be happy with the help!

Thanks for your help for now though!
Mugen Wizardry
User Banned
Posted: 1st Dec 2010 17:59
I agree with Mad Nightmare. Using a UDT is the best way to go.

Although I redid his function a bit so you have more control over it

function create_unit( x#,y#,z#,maxenemies )
for i = 1 to maxenemies `loop through the units array
if units( i ).obj = 0 `if the index is not in use
unit = i `then use this index
exit
endif
next i

units( unit ).obj = find free object() `find a free obj id
units( unit ).x# = x#
units( unit ).y# = y#
units( unit ).z# = z#

make object cube units( unit ).obj, 1 `make the object with the free id

endfunction unit

Enjoy!

~MW~

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Dec 2010 18:05
@Mugen Wizardry: maxenemies would be a global or constant, it wouldn't be a variable that changes with each function call, so it shouldn't be in the function parameters.

MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 2nd Dec 2010 00:42
I have used Tupp3 suggestion.

however i need to use a minus in z axis

like this below

position object e, rnd(2000), 0, rnd(-2000)

The objects are lined across the x axis. But dont fall into the y.

What do i need to do?
TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 2nd Dec 2010 11:28 Edited at: 2nd Dec 2010 13:07
I would also recommend using UDT and arrays for multiple enemies, it's lot easier and faster after you do the bit more complicated initialization.

But to achieve positive and negative random value you can use
rnd(2000)-rnd(2000)

That will return random number between -2000 and +2000.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 2nd Dec 2010 16:54
rnd(2000)-rnd(2000)

For what it's worth, rnd(4000) - 2000 would be slightly faster I imagine. But both perform the same function of course.

MightyRy
15
Years of Service
User Offline
Joined: 19th Oct 2010
Location:
Posted: 3rd Dec 2010 09:13 Edited at: 3rd Dec 2010 09:55
If i wanted to limit the rnd so that its between 100 to 300 on x axis and 500 to 800 on the z axis.

so that the models are in a ceratin area!

Is it possible, how would that work?
TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 3rd Dec 2010 11:55 Edited at: 3rd Dec 2010 11:56
x=100+rnd(200)
z=500+rnd(300)

position object Objnumber, x,0,z
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 3rd Dec 2010 15:05
To work out the values to use for the rnd() function, you just need to think about these two things. What is the range of values you desire? Call this variable A, and what is the minimum possible variable? Call this variable B.

You can then put this in code format:



Which would pick a random value between 50 and 150

In function format:



Nightmare

Login to post a reply

Server time is: 2026-07-21 13:38:46
Your offset time is: 2026-07-21 13:38:46