The Daily Click ::. Forums ::. Klik Coding Help ::. help with range detection
 

Post Reply  Post Oekaki 
 

Posted By Message

underjoyed



Registered
  02/07/2003
Points
  112
3rd August, 2003 at 13:06:48 -

...I know this question has been on the board before but I'm having some problems.I need to know how to make range detection in my game, I've downloaded the Angle calculater extention but I can't get it to work when I have more then one object of that same type...I've downloaded Tigerworks's RTS open source but it was confusing to me (I don't really know fastlooping)...anyways, if anyone could make a small tutorial for me or help me thanks.


 
-underjoyed

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
3rd August, 2003 at 13:17:39 -

range is easy
((playerx+targetX)+(playerY+tagertY)) / 2

 
Craps, I'm an old man!

underjoyed



Registered
  02/07/2003
Points
  112
3rd August, 2003 at 13:26:16 -

where do I put that?

 
-underjoyed

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
3rd August, 2003 at 13:30:13 -

that's the formula for finding out range, put it where you need it.

 
Craps, I'm an old man!

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
3rd August, 2003 at 13:30:52 -

sqrt((X2-X1)²+(Y2-Y1)²)

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
3rd August, 2003 at 13:32:07 -

that's the more precise formula

 
Craps, I'm an old man!

Aali [Crazy_Productions]



Registered
  13/10/2002
Points
  843
3rd August, 2003 at 13:42:35 -

correct me if i'm wrong but i think he meant that the range detection works fine, but not when there's more than one of the same object

and for that you'll have to learn how to use the fastloop

 
"If Darl McBride was in charge, he'd probably make marriage unconstitutional too, since clearly it de-emphasizes the commercial nature of normal human interaction, and probably is a major impediment to the commercial growth of prostitution."
-- Linus Torvalds, December 5th 2003.

(Darl McBride is CEO of The SCO Group)


this place sucks but don't tell anyone, it's our little secret, ok?

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
3rd August, 2003 at 13:47:34 -

use a value to set the internal flag of the target to 1, that would differentiate between 2 of the same object.

 
Craps, I'm an old man!

underjoyed



Registered
  02/07/2003
Points
  112
3rd August, 2003 at 14:21:02 -

when I use the Angle calculator extention object and do -The distance between "object 1" and "object 2" is lower then 150"- object 1 is supposed to shoot "object 2" but instead it shoots only the last "object 2" that I made...you probably won't understand that if you dont have Angle calculator

 
-underjoyed

underjoyed



Registered
  02/07/2003
Points
  112
3rd August, 2003 at 15:00:43 -

and about the formulas...how would I code "object 1 shoots object 2 when it is ____close to object 2"?
in other words, how would I make objects shoot each other when their close to each other? but tell me how it would look in code...thanks

 
-underjoyed

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
3rd August, 2003 at 17:40:21 -

Do new condition (Select "compare two general values")
When sqrt((X2-X1)²+(Y2-Y1)²) is lower than 150
Then Player 1 shoot in direction of Player 2

 
n/a

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
3rd August, 2003 at 18:16:50 -

Yay! I had a go in making this work!

The formulas by Shab and Kris A didnt work for me for some strange reason, so i used
(X("Player 2")-X("Player 1"))/Cos(ACos((X("Player 2")-X("Player 1"))/(Y("Player 2")-Y("Player 1")))

Pick one (Player 2) at random
When (formula)is greater that 0
And (formula) is less than 150
- Player 1 shoot at player 2

And because player 2's x position can be less than player 1's, do another event fo when formula is less than 0 and above -150.
Even though its not a great method, by using Pick at random you can make the player shoot at all other players the easiest way, without is shooting at the most recent created.

Thank you, thankyou, man im good,
hope this works for you, if it doesnt i can email you my example

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
3rd August, 2003 at 19:30:53 -

yeah, if you tried to square the number with the little '2', it's going to fail because most expression doodads don't process it

(just multiply the number by itself instead)

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G
   

Post Reply



 



Advertisement

Worth A Click