The Daily Click ::. Forums ::. Klik Coding Help ::. How to make player face the mouse with the angle command?
 

Post Reply  Post Oekaki 
 

Posted By Message

Jon C-B

I create vaporware

Registered
  23/04/2008
Points
  237

I'm an alien!VIP MemberWii OwnerI donated an open source project Santa Hat
27th February, 2010 at 03:35:19 -

I'm trying to make the player in my game face the mouse, and I think it would be better to use the angle expression rather than 32 directions. But what ever I try doesn't work. Can anyone help?

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2010 at 03:53:08 -

you need the advanced math object for starters

-start of frame
+set fixed object to (your character)

-always
+set angle of (your character) to FixedAngle( "Advanced Math object", XMouse, YMouse)

Edited by Cecilectomy

 
n/a

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
27th February, 2010 at 03:59:51 -

I prefer to use the Advanced Direction Object, as it doesn't require a fixed object:
Always: Set angle of Active to Direction( "Advanced Direction Object", X( "Active" ),Y( "Active" ),Xmouse,Ymouse)

Edited by an Administrator

 
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

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
27th February, 2010 at 03:59:58 -

or even simpler...

+ Always
-> Player: Set angle to ATan2(Y("Player") - YMouse, XMouse - X("Player"))

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
27th February, 2010 at 04:01:02 -


Originally Posted by Sketchy
or even simpler...

+ Always
-> Player: Set angle to ATan2(Y("Player") - YMouse, XMouse - X("Player"))



Use this. It's more awesome if you do it without extensions.

/uselesspost

 

  		
  		

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
27th February, 2010 at 04:01:05 -

You could use ATan2(). It finds the angle between two objects, using this form: ATan2(X("Active 2")-X("Active"),Y("Active 2")-Y("Active")). You might have to add or subtract 90 to make it the correct angle, I never could remember which and it always seemed to be different. You could also use the Advanced Direction object (or Advanced Math, I've not used either so I wouldn't know which) to do the math. From there it's just a matter of setting the angle to the result of that formula.

EDIT: Nevermind everyone else got it.

Edited by an Administrator

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2010 at 04:03:34 -

curse you sketchy! you and your maths!

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
27th February, 2010 at 04:05:46 -

If you do it in the order I wrote it (ie. "yA-yB, xB-xA") you don't need to add/subtract 90 degrees or whatever.
It's just one of the weird side-effects of the Y axis being inverted.

 
n/a

Jon C-B

I create vaporware

Registered
  23/04/2008
Points
  237

I'm an alien!VIP MemberWii OwnerI donated an open source project Santa Hat
27th February, 2010 at 04:24:16 -

Dang, that expression makes no sense, Tan and Sin are sort of covered next year. But thanks! It works great.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
27th February, 2010 at 16:25:26 -

I don't thing ATan2 is a "proper" trigonometric function exactly - it's kind of an algorithm that computer programmers invented. It certainly never got a mention in maths classes when I was at school.

Edited by Sketchy

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
27th February, 2010 at 21:34:31 -

"The atan2 function was first introduced in computer programming languages, but now it is also common in other fields of science and engineering."

http://en.wikipedia.org/wiki/Atan2

 
n/a

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
1st March, 2010 at 09:53:00 -

ATan isn't really a "proper" method, only makes computing easier. If you use a "proper" Tan, it gets the bottom quadrant upside down, and ATan gets for use in practical applications (like this). Yeah, they should be teaching you the problems of a normal Tan in school.

What Sketchy's formula does is that it just calculates the angle, since Tan uses the ratio between the Y and X to get you the angle.


Anyway, Jon, here's an article I wrote on trigonometry:
http://www.create-games.com/article.asp?id=1984

Should cover Cos and Sin, but I left out Tan, lol. It's a bit better than what I learned in school; I find that a lot of my teachers can teach what it is but have no idea how to use it :/ I'll add a section on Tan if you want

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image
   

Post Reply



 



Advertisement

Worth A Click