The Daily Click ::. Forums ::. Klik Coding Help ::. Calculating a distance between 2 objects
 

Post Reply  Post Oekaki 
 

Posted By Message

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
15th October, 2008 at 11:21:16 -

Hello there
I currently have a little project, and I need to calculate just about all the time the distance between an object that will be assigned to the mouse and another object, and there's a difference in what happens the further they are (there are 3 levels of distance possible).

Anyway I've been wondering, considering this is supposed to be a pretty object-heavy frame, what's a better approach - creating 2 invisible circular active objects to move with the non-mouse object, and they will represent different radiuses of distance from the player, and once you overlap one of them with the mouse - the appropriate action;
or the other option being 3 events using the Pythagoras theorem.

In "better approach" I mean what would be more efficient to do, because that's one of the most basic elements in this application, and I wouldn't want to find out later that what I created is too processor intensive because I cut corners on such things.


Thanks!

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
15th October, 2008 at 11:40:10 -

There are extensions like math and direction objects I believe, but I don't like using extensions to do simple tasks. Your best bet would be to just use a distance formula imho.
SquareRoot((x1+x2)^2*(y1+y2)^2)
I'm sure I'm going to look like a dumbass if I got that wrong, but it's been a while and I don't feel like looking it up.

 
http://www.facebook.com/truediamondgame

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
15th October, 2008 at 11:50:44 -

its actually a very cumbersome formula to implement over and over again in a game. Use the advanced math object, it has it as one of the options, and is highly efficient.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
15th October, 2008 at 16:08:06 -

Thanks, I searched for the advanced math object and it directed me to Cellsoft's website and a 404 error, does anyone happen to have the object uploaded somewhere? (MMF2)

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Willy C



Registered
  14/02/2004
Points
  1524

Game of the Week WinnerKlikCast StarPicture Me This -Round8- Winner!VIP MemberWii OwnerIt's-a me, Mario!Hero of TimeThe Cake is a LiePS3 OwnerI am an April Fool
Batman!Teddy Bear
15th October, 2008 at 17:30:34 -

Maybe this will help?

Darkwing's Distance Checker
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=110168#Post110168

Image Edited by the Author.

 
http://www.robocaptain.com

aphant



Registered
  18/05/2008
Points
  1242
15th October, 2008 at 18:37:57 -


Originally Posted by Pixelthief
its actually a very cumbersome formula to implement over and over again in a game. Use the advanced math object, it has it as one of the options, and is highly efficient.



Couldn't it be coded as a behaviour of the mouse object? The only problem a behaviour though is the lack of qualifiers.

 

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
15th October, 2008 at 20:31:45 -

This questions gets asked far too many times.

 
My signature is never too big!!!

-MacAdaM-

Megaman Fosho

Registered
  12/02/2008
Points
  560
16th October, 2008 at 01:22:04 -

Distance = Sqr(((A.x - B.x)*(A.x - B.x)) + ((A.x - B.x)*(A.x - B.x)))

This is according to Sketchy's article.
http://create-games.com/article.asp?id=1898

 
Your just jealous that you're not as awesome as me.
(And my megaman avatar )

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
18th October, 2008 at 02:12:03 -


Originally Posted by MacAdaM
Distance = Sqr(((A.x - B.x)*(A.x - B.x)) + ((A.x - B.x)*(A.x - B.x)))

This is according to Sketchy's article.
http://create-games.com/article.asp?id=1898

I think you missed my actual question.
Anyway thanks everybody!

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445
   

Post Reply



 



Advertisement

Worth A Click