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 / Enemies firing at player?

Author
Message
maowan
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location:
Posted: 22nd Apr 2003 17:02
Can anyone help,

Is there a simple script that I can incorperate into my game, which controls a function that if my player is a certain distance from an enemy,the enemy will continuously shoot bullets at the player, in the direction of the player?
koolaid
21
Years of Service
User Offline
Joined: 26th Jan 2003
Location: Cyberspace
Posted: 23rd Apr 2003 07:13
im well theres a simple math to get the distance beteween two objects(player and enemy)its also in the tutorials.if you cant find it ill post it for you.
pdist=sqrt((myxpos# - enemyxpos#)^2 + (myypos# - enemyypos#)^2 +(myzpos# - enemyzpos#)^2)
then make a loop if player distance is within whatever range do whatever(enemy shoot at player)
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 02:14
Interesting.. I read it and I can't understand why it works? Could anyone break down that Equation to better help us math-ignorant peeps to understand?
PiratSS
21
Years of Service
User Offline
Joined: 18th Oct 2002
Location:
Posted: 27th Apr 2003 05:13
ok
distance=square root of((Your current x position-Enemy's current X position) to the power of 2 + (Your current Z position-Enemy's current Z position) to the power of 2)

Cheers.

There are two types of people in the world: The ones who summon and the ones that create. There is a big difference...
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 07:21 Edited at: 27th Apr 2003 07:24
Thanks!

After reading how the expression works. I scrambled to do it by long hand..

First

I drew a 10x20 Grid.. I'll just do a 8x8 grid
<--------X--------->
0|1|2|3|4|5|6|7|8|
1|o|o|o|o|o|o|o|o|
2|o|o|o|o|o|o|o|o|
3|o|A|o|o|o|o|o|o|
4|o|o|o|o|o|o|o|o|
5|o|o|o|o|o|B|o|o|
6|o|o|o|o|o|o|o|o|
7|o|o|o|o|o|o|o|o|
8|o|o|o|o|o|o|o|o|

As you can see.. A is located at 2,3 and B is located at 6,5.
so aX is 2 and bX is 6
and aY is 3 and bY is 5

So it would be sqrt((aX-bX)^2 + (aY-bY)^2)

first we figure out what aX-bX is ... (2-6) = -4
2nd we figure out what aY-bY is ... (5-6) = -1
3rd we figure out what -4^2 is .. (-4^2) = 16
4th we figure out what -1^2 is .. (-1^2) = 1
5th we add 16 and 1 which is 17
6th we find the square root of 17 which is 4.123105626

If you try to figure out the distance by counting the squares you'll not be able to get a decimal.. but you can only say that A is 4 squares west from B and 2 squares north from B .. But since it is kinda diagnal you mathematically get 4.1 .. I'm not 100% but I did the math. and I know that this is pretty close..

Thanks! I enjoyed doing the math

I'm still stuck on trying to figure out how to make the enemy turn to face the player.. And I'm only thinking that I must learn math in order to do this.. But would I need to learn trig to do that?
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 27th Apr 2003 12:55
px#=object position x(player)
py#=object position y(player)
pz#=object position z(player)
point object enemy px#,py#,pz#
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 29th Apr 2003 15:31
Well, I just wanted to thank a user named "Easily Confused" for showing me how to get the angle!! Well, for 2D.. Which I'm working on atm.. 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!!

Login to post a reply

Server time is: 2024-09-20 05:25:21
Your offset time is: 2024-09-20 05:25:21