The Daily Click ::. Forums ::. Klik Coding Help ::. Set Angle to lock on to mouse coordinates?
 

Post Reply  Post Oekaki 
 

Posted By Message

chrilley

Insane Beaver

Registered
  05/01/2002
Points
  704

Game of the Week WinnerVIP Member360 Owner
25th November, 2007 at 05:35:22 -

Hiya, trying to make a game where the character's arms are supposed to be rotated in the direction where the mouse pointer is. I'm using the "Set angle" condition. Anyone happen to have some formula or trick up their sleeve that I could use?

 
Image

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
25th November, 2007 at 05:44:10 -

I'm sure something like this should work

[Pseudo Code]
Atan((Y(Mouse)-Y(Arm)) / (X(Mouse)-X(Arm)))

 
n/a

chrilley

Insane Beaver

Registered
  05/01/2002
Points
  704

Game of the Week WinnerVIP Member360 Owner
25th November, 2007 at 06:24:55 -

Couldn't get it to work properly, did I do it wrong?

ATan((Y( "mouse" )-Y( "right arm: empty" ))/(X( "mouse" )-X( "right arm: empty" )))

 
Image

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
25th November, 2007 at 07:34:24 -

I thought ATan in MMF didn't work properly?

 
191 / 9999 * 7 + 191 * 7

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
25th November, 2007 at 10:39:10 -

Atan returns the result in radians.

pi radians = 180 degrees.

to convert, multiply by 180/pi

aka:

Atan((Y(Mouse)-Y(Arm)) / (X(Mouse)-X(Arm))) * 57.3


Image Edited by the Author.

 
My signature is never too big!!!

chrilley

Insane Beaver

Registered
  05/01/2002
Points
  704

Game of the Week WinnerVIP Member360 Owner
25th November, 2007 at 14:44:17 -

That didn't work either. The arm is just spinning like crazy. And when the pointer is too far away it won't respond anymore. Is there some example somewhere I could use?

 
Image

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
25th November, 2007 at 15:47:40 -

Try using the advanced direction object.

You can get the angle between 2 objects with 1 condition, I believe.

 
My signature is never too big!!!

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
25th November, 2007 at 17:13:12 -

Can't you make the arm as a separate objected glued to the player? Then give the arm 32 directions and set it to always look towards the mouse pointer.

If your player character is small, the user won't notice the small graphical glitches that is caused by the few 32 angles. And if you character is a little larger, using the rotate function will make the program run slow.

 
http://www.robocaptain.com

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
25th November, 2007 at 23:50:51 -

I would simply used the Advanced Direction Object, then use one of its actions to get the direction between two points. You would simply have to set the direction of the arm to that.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

\/\/olf

Creative Genius

Registered
  06/08/2005
Points
  76

VIP Member
26th November, 2007 at 02:26:15 -

The Atan thing works perfectly. I asked about 2 weeks ago. Just need to convert it to degrees. Thats it. It takes two events.

One for Xmouse is greater than XArm
180 - ATan((Y( "mouse" )-Y( "right arm: empty" ))/(X( "mouse" )-X( "right arm: empty" )))

and one for Xmouse is smaller than Xarm.
0 -ATan((Y( "mouse" )-Y( "right arm: empty" ))/(X( "mouse" )-X( "right arm: empty" )))

I think its that way. Try reversing them. It should work. You also have to convert it to degrees by dividing it the whole result by Pi and multiplying it by 180.

Image Edited by the Author.

 
Image

www.OldMansTale.net
Sign the Petition! Go go Go!!

chrilley

Insane Beaver

Registered
  05/01/2002
Points
  704

Game of the Week WinnerVIP Member360 Owner
26th November, 2007 at 04:19:32 -

Advanced Direction Object worked wonders. Thanks

 
Image
   

Post Reply



 



Advertisement

Worth A Click