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 / Enemy detecting player

Author
Message
Enlightened Gamer
14
Years of Service
User Offline
Joined: 4th Oct 2009
Location:
Posted: 16th Oct 2009 01:37
Hey guys,

I have yet another question lol...

I am trying to get a "enemy" to detect if the player is close.

I have tried to do this by detecting if the X & Z of the enemy (object 4) are closer then 50 to the camera, if so then the enemy should turn to face the camera and charge it.

All attempts have failed badly! I have looked at the example "iced" but I really cant understand what the code means so I cant transform it to work for my code.

Is there a simplish way of doing this?

It is really frustrating when you think you have got it spot on and then you run the program and it does nothing or does something completely different to what you were expecting lol

Thanks in advance for your advice.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Oct 2009 02:28
A distance check should suffice. Find the distance between the player and the enemy:



This is really the pythagrean formula without the square root. It takes the input of 2 objects, and the maximum distance you want to check between the 2. If the objects are within that maximum distance, the function returns a 1. Here is and example of it working:



Each square on the matrix is 100 units, so when the cube is within 1 square of the sphere, the distance check should flag true (I set maxdist# to 100).

Enjoy your day.
Bluestar4
18
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 22nd Oct 2009 06:48
as far as enemies moving toward the player you will also need to possibly get the basic angle of the player from the enemy so that you can make it turn smoothly.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Oct 2009 23:56
You'll also need to take the enemy's Y angle into account if you don't want him to automatically turn round when the player gets withing the specified distance.

Using just distance, you wouldn't be able to creep up on an enemy and he would 'see' you even when facing the other way.

To fix this, simply imagine an arc of say 100 degrees (50 degrees either side of the angle the enemy is facing).

If you calculate the angle of the player from the enemy and this value doesn't fall in the viewing angle range then the enemy wouldn't automatically turn around the instant the player got within range.

If the enemy is within the specified distance AND the player falls within this view arc then the enemy turns to face the player and does whatever.

TDK

Login to post a reply

Server time is: 2024-05-04 01:54:19
Your offset time is: 2024-05-04 01:54:19