Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Rotation According To Joystick Direction  (Read 2381 times)

0 Members and 1 Guest are viewing this topic.

Tylernocks

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Rotation According To Joystick Direction
« on: June 23, 2013, 10:51:14 am »
I am referring to SFML2 and I was wondering if It were possible (if so how) to make it where the sprites rotation is changed based on joystick direction (for example if I were to move the left stick somewhere between up and right, it would match that angle) or something kinda like it where is detects where the joystick direction is and sets it rotation here like if my stick was between down and left it would be 45 degrees.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Rotation According To Joystick Direction
« Reply #1 on: June 23, 2013, 10:53:33 am »
Yes, it's possible. Please read the tutorials and the API documentation.

If you encounter any problems, you can still ask specific questions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tylernocks

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Rotation According To Joystick Direction
« Reply #2 on: June 23, 2013, 11:15:35 am »
I was looking through the docs and tutorials and I see you can rotate but I didn't find out  how to convert joystick direction to a setRotation.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Rotation According To Joystick Direction
« Reply #3 on: June 23, 2013, 02:21:19 pm »
Use the atan2 math function and convert the resulting radians to degrees.

mayday556

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Rotation According To Joystick Direction
« Reply #4 on: December 04, 2013, 12:37:06 am »
Use the atan2 math function on what resulting radians

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Rotation According To Joystick Direction
« Reply #5 on: December 04, 2013, 01:25:21 pm »
You seriously registered to dig out a half year old thread and ask a vague question?

Anyway, it's easy to figure that out if you read the atan2() documentation (e.g. on cppreference.com). This function takes a y and x value and returns the polar angle of the corresponding vector. Like for all angles in the standard library, radians are used.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: