Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Joystick Help

Author
Message
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 15th Feb 2011 07:27
So how the joystick works is I have vertical and horizontal which means when I push straight up on the joystick the Vertical is at 1.0f and when I push down on the stick it is at -1.0f. same goes for the Horizontal 1.0f to the right and -1.0f to the left. So the game is a top down so all I want to do is have my character face and shoot in the direction of where I point the joystick. So how would I take the data that I have and convert that into the Yaw rotation of the sprite?
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 16th Feb 2011 04:53 Edited at: 16th Feb 2011 04:56
Geometry. simple google search:
Quote: "

If you divide {x,y} by its length sqrt(x^2+y^2), then you have a
vector of unit length:

{x/sqrt(x^2+y^2),y/sqrt(x^2+y^2)}

There is a unique number t between 0 and 2pi (or between 0 and 360)
such that:

cos(t) = x/sqrt(x^2+y^2)

and

sin(t) = y/sqrt(x^2+y^2)

t is the angle you want.

- Doctor Jerry, The Math Forum
http://mathforum.org/dr.math/

"


Now, you just isolate t and you get

t = acos(x/sqrt(x^2+y^2))
t = asin(y/sqrt(x^2+y^2))

x and y are simply the x and y axis of the controller. so it generaly is a vector from 0,0 to x,y do a search on vectors and you might get your result

hi
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 16th Feb 2011 05:54
Thanks! the Achilles heel of programming for me is math :\ I didn't even have an idea of what to search for. This helps a lot thanks again.

Login to post a reply

Server time is: 2024-11-19 14:34:50
Your offset time is: 2024-11-19 14:34:50