I was thinking of creating a game that looks like Chaos Emerald Hunting from Sonic Adventure DX and Sonic Adventure 2.
For those who don't know what it is, well, it's basically a "cold... very cold... getting warmer... warm... hot!... warm... hot! Bingo!"
Well, the problem is: I can do a random to put the 3 pieces on random spots, and the closer you are to them, the on-screen radar will change. Except that: Is there any way to calculate the distance difference between the main character's X and Y and one of the pieces X and Y?
Measuring Distances Between Objects?
Started by
Espyo
, Apr 09 2008 05:49 PM
4 replies to this topic
#1
Posted 09 April 2008 - 05:49 PM
#2
Posted 09 April 2008 - 06:23 PM
Hey Espyo!
To calculate the distance between two points you can use the distance forumula. You need two coordinates:
x1, y1 (Could be the main player)
x2, y2 (Could be an enemy)
Here's the forumula:
distance = sqrt( (x2-x1)^2 + (y2-y1)^2 )
To calculate the distance between two points you can use the distance forumula. You need two coordinates:
x1, y1 (Could be the main player)
x2, y2 (Could be an enemy)
Here's the forumula:
distance = sqrt( (x2-x1)^2 + (y2-y1)^2 )
#3
Posted 09 April 2008 - 07:49 PM
Y'all might recognize that as the Pythagorean Theorem that gives the length of the hypotenuse of a right triangle.
Tom Lake
Tom Lake
#4
Posted 09 April 2008 - 10:05 PM
I would not use the "power" function "^" though, to calculate the square, it takes much more time to calculate than the direct square function (uppercase "2").
distance = sqrt( (x2-x1)2+ (y2-y1)2 )
Or use a direct calculation: distance = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) )
If you need an even faster calculation, leave out the "sqrt", then you will have the square of the distance, which is just as useful to judge proximity of two points.
For instance a result of "100" means the distance is 10, "25" means the distance is 5, etc.
distance = sqrt( (x2-x1)2+ (y2-y1)2 )
Or use a direct calculation: distance = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) )
If you need an even faster calculation, leave out the "sqrt", then you will have the square of the distance, which is just as useful to judge proximity of two points.
For instance a result of "100" means the distance is 10, "25" means the distance is 5, etc.
#5
Posted 12 April 2008 - 02:46 PM
Oh, so that's how!
Thanks a bunch everyone ;D
Thanks a bunch everyone ;D
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users


