The Daily Click ::. Forums ::. Klik Coding Help ::. Calculating distance
 

Post Reply  Post Oekaki 
 

Posted By Message

hapsi



Registered
  13/11/2003
Points
  775
6th October, 2006 at 13:14:37 -

How can i calculate the distance between 2 objects using tgf.

 
[Signature][/Signature]

David Newton (DavidN)

Invisible

Registered
  27/10/2002
Points
  8322

Honored Admin Alumnus
6th October, 2006 at 13:31:46 -

Use the Distance Formula - the distance between two objects is Sqrt((X2-X1)^2 + (Y2-Y1)^2). At least, I hope it is, because I realized that I had completely forgotten it when I hit Reply.

 
http://www.davidn.co.nr - Games, music, living in America

axel

Crazy?

Registered
  05/02/2005
Points
  4766

Game of the Week WinnerYou've Been Circy'd!
6th October, 2006 at 13:47:22 -

It's Sqr((X2-X1) Pow 2 + (Y2-Y1) Pow 2) in MMF. I'm not sure if the power and square root functions work in TGF though.

Image Edited by the Author.

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
6th October, 2006 at 13:51:56 -

I'm sure there are extensions that do this for you, or at least there's an extension which provides square root in TGF.

try http://click.spatang.com (TGF/MMF extension lists)

 
191 / 9999 * 7 + 191 * 7

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
6th October, 2006 at 14:25:12 -

well done all those that know basic pythagoras theorem rules

 
My signature is never too big!!!

hapsi



Registered
  13/11/2003
Points
  775
7th October, 2006 at 04:06:06 -

There is no extension for tgf/cnc that could calculate the distance directly. I have tried to do this with advantech math object like this, but it did'nt work..?

Allways: set counter to:
Sqrt( "Advanced Math object 2", ( X( "Player hitbox" ) - X( "sound creator 1" )) Pow( "Advanced Math object 2", 2 ) + ( Y( "Player hitbox" ) - Y( "sound creator 1" )) Pow( "Advanced Math object 2", 2 ) )

 
[Signature][/Signature]

Werbad



Registered
  18/09/2002
Points
  235
7th October, 2006 at 06:29:10 -

Doesn't Avanced math object have a get distance between two points function?

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
7th October, 2006 at 08:30:06 -

Yes it have.. but condition only, so i cant do event allways: set counter to "distance"

 
[Signature][/Signature]

hapsi



Registered
  13/11/2003
Points
  775
7th October, 2006 at 10:04:01 -

Oh there is "Distance from fixed object to x,y" but i cant define position of the other object.. only thing i can define is just one number ---> FixedDist( "Advanced Math object 2", 0 ). What's that supposed to mean? And if i put it like that i get syntax error.

 
[Signature][/Signature]

hapsi



Registered
  13/11/2003
Points
  775
7th October, 2006 at 14:51:15 -

I have set the fixed object--> Start of frame: Set fixed object to (object)

 
[Signature][/Signature]

Werbad



Registered
  18/09/2002
Points
  235
7th October, 2006 at 16:45:21 -

Isn't there one for "Distance from 0,0 to x,y" aswell?
Just use:
Dist("Advanced Math object", X("Object 1") - X("Object 2"), Y("Object 1") - Y("Object 2"))

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
10th October, 2006 at 10:13:33 -

Dist( "Advanced Math object", X( "Player hitbox" ) - X( "sound creator 1"), Y( "Player hitbox" ) - Y( "sound creator 1" ) )

Gives syntax error.. i know i should use mmf but i dont like its interface.

Image Edited by the Author.

 
[Signature][/Signature]

hapsi



Registered
  13/11/2003
Points
  775
14th October, 2006 at 10:19:34 -

I solved the problem:
FixedDist( "Advanced Math object 2", ( X( "sound creator 1" ) ), Y( "sound creator 1" ) )

 
[Signature][/Signature]
   

Post Reply



 



Advertisement

Worth A Click