The Daily Click ::. Forums ::. Klik Coding Help ::. finding distance in mmf2
 

Post Reply  Post Oekaki 
 

Posted By Message

Wicked Studios



Registered
  25/10/2004
Points
  460
22nd August, 2006 at 17:28:31 -

I'm making some bullets that home in on enemies for a game, and i wanted it so when they are about 50 pixels away from and enemy, they will chase it. Problem is, theres no angle calculator for MMF2 and i can't quite get the distance formula to work for me (maybe a little help with that?) so if anyone can help or has any ideas, I'd really appreciate it.

 
"Actually sir, we found a tiny unicorn in your exhaust. It was jumping around poking holes in your gas tank." "Oh thank you I did not know that. A tiny unicorn? Wow."

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
22nd August, 2006 at 17:32:50 -

No angle calculator? Browse through the forums better.
http://www.create-games.com/forum_post.asp?id=166186

OKAY NOW THIS IS A USE TO SOMEONE APPARENTLY

You could also do: when the x of the bullet > the x of the enemy - 50 AND when the bullet x < enemy x + 50 AND these two for the Y, toggle a flag that makes the bullet chase the enemy.

 
Old member (~2004-2007).

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
22nd August, 2006 at 22:44:05 -

I'm not sure what the hell you just said so I'll just give him the answer.

Distance formula is: sqrt((y1-y2)^2+(x1-x2)^2)

Which in klik looks a little something like this: Sqr( ( ( X( "Object 1" ) - X( "Object 2" ) ) * ( X( "Object 1" ) - X( "Object 2" ) ) ) + ( ( Y( "Object 1" ) - Y( "Object 2" ) ) * ( Y( "Object 1" ) - Y( "Object 2" ) ) ) )

I'm sure there are extensions to make it easier but that's pretty much what I do.

 
n/a

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
23rd August, 2006 at 01:34:27 -

You can also make your expressions a little tidier by using "pow" to raise the distances to the second power.
You just have to remember that its syntax isn't like "pow(x,y)", but rather "x pow y".

 
Go Moon!

Werbad



Registered
  18/09/2002
Points
  235
24th August, 2006 at 10:41:34 -

Sqr( ( X( "Object 1" ) - X( "Object 2" ) ) pow 2 + ( Y( "Object 1" ) - Y( "Object 2" ) ) pow 2 )

 
n/a

Deleted User
24th August, 2006 at 11:37:17 -

Sqr and pow? O.o Whats that?

 

Alice Pierce



Registered
  08/01/2006
Points
  6
24th August, 2006 at 12:16:20 -

X Power Y = X*X*...*X }Y times
e.g. 3 pow 4 = 3*3*3*3, 7 pow 2 = 7*7
Squarte of X = Y only if Y*Y = X
e.g. Sqrt 4 = 2 cause 2*2=4, Sqrt 25 = 5 cause 5*5 = 25
Now you understand it?


 
;]

Deleted User
24th August, 2006 at 12:18:25 -

Yeah, thanks alot.
Now it all makes sense.

 

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
24th August, 2006 at 15:45:45 -

Squarte? Square root.
Pow is power. Like 2^5 (or 2 pow 5) is 2*2*2*2*2.

 
Old member (~2004-2007).

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
24th August, 2006 at 20:30:25 -

you could also do 2^(1/5), to get the 5th root, could you not?

I've never tried this... Someone try it and tell me

(Also might consider trying a^(x/y) i.e 2^(3/2) to give the square root of 2 cubed... I've never tried it in mmf, if it works it could be useful for saving on coding if it were ever used... not useful in this situation though, as it has to be the square root((X difference)² + (Y difference)²))

You could also get the angle using tan (y difference/x difference) but i think MMF has tan angles in radians... easy to convert to degrees though, (1 radian = 180/pi degrees)

uh... yeah

 
My signature is never too big!!!

Werbad



Registered
  18/09/2002
Points
  235
25th August, 2006 at 02:21:39 -

I think aTan is used when calculating angles

 
n/a

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
25th August, 2006 at 02:47:49 -

^ I think so too, unless I just code wrong.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
25th August, 2006 at 07:28:28 -

uh... no, you're right, i just wrote that at about 1am, when i was very tired

 
My signature is never too big!!!

Flava



Registered
  30/07/2002
Points
  684

Has Donated, Thank You!Code MonkeyVIP MemberThe Cake is a LieThe Spinster
25th August, 2006 at 07:37:05 -

Try using the advanced direction object?
It was converted to MMF2 and can find the distance between two points (if that is what you want - I haven't read the post fully to be honest)

 
This is a signature. Have this one on me.

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
25th August, 2006 at 10:57:09 -

Distance formula isn't too hard. Generally you're better doing it manually as to dodge the extension overhead. I've been doing it that way since KNP.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click