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 / Probs with simple AI

Author
Message
Sir Spaghetti Code
20
Years of Service
User Offline
Joined: 12th Jul 2004
Location: Just left of Hell
Posted: 15th Aug 2004 01:38
Hello. What I am trying to do here is to set it so that when my monster is facing another direction besides the player, he will turn in that direction. When he is completely facing the player he will begin to move forward after him.

This is my first attempt at very simplistic enemy AI. I'm not sure why it is not working. The enemy will still move on my command, but he will not turn to face the player. I have REMed out the area that I tried to code this. Any help is very appreciated!!

Any Ideas?

"I attribute the quarrelsome nature of the Middle Ages young men entirely to the want of the soothing weed."
-Jerome K. Jerome(1859-1927),Writer
future boy
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: In a virus
Posted: 15th Aug 2004 02:15
check out that iced game (if you have dark basic classic)

or download it off the dark basic website (which is this website)

[img]www.freewebs.com/southernfuturegames/contactme.htm/head1.gif[/img] www.thechroniclesofriddick.com
future boy
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: In a virus
Posted: 15th Aug 2004 02:17
Or find a source code in the code base,

I'll find one for you!

[img]www.freewebs.com/southernfuturegames/head1.gif[/img] www.thechroniclesofriddick.com
Physics coder
20
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 17th Aug 2004 14:31
I don't have time to look at all your code, but it should be easy to do. IF you can, take the idea of this pesudo-code, and substitute in your game's objects, variables, whatever.


Get the angle From the monster to the player, like this, but with your monsters x/z position and players x/z position

target_angle=wrapvalue(atanfull(playerx-monsterx,playerz-mosterz))
`next get the angle of the monster, subsitute this for the actual y angle of the monster, usually object angle y(monster_obj) or something:

y_angle=wrapvalue(monsteryangle)

`find the difference:
turn_angle=wrapvalue(target_angle-current_angle)

`then make any angle above 180 negative, (example: instead of turning 270 degrees right, he turns 90 left instead.)

`example: 270-360=-90, so he turns left if it's the shorter way to turn
if turn_angle>180 then dec turn_angle,360

`now, make your own functions or run whatever code that turns the monster:
if turn_angle>0 then turn_right(monster)
if turn_angle<0 then turn_left(monster)

`if facing player, more forward:

if abs(turn_angle)<20 then walk_forward(monster)

-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.

Login to post a reply

Server time is: 2024-09-22 21:28:03
Your offset time is: 2024-09-22 21:28:03