### Autor Tema: Corresponding analog stick state to angle of sprite  (Leído 1828 veces)

#### FusekiGames

• Newbie
• Mensajes: 4
• Karma: 0
##### Corresponding analog stick state to angle of sprite
« en: Enero 04, 2017, 04:14:14 am »
Hello! I'm attempting to rewrite the controller code to my soon-to-be-released Dreamcast game, and I'd like to have the analog stick determine the angle that the plane is pointing at. For example, the player points the stick to the upper right, and the ship immediately points to that angle. As the player rotates the stick, the point of the ship follows that angle. The old coin-op arcade game Time Pilot is a good example of what I'm trying to accomplish. I've done a ton of research on how to accomplish this, but can't seem to figure it out. Anyone have any ideas that I can try?

Is there a way to convert the joystick axes to angles?

Thanks in advance for any help.

EDIT: Ok... I am SOOOO close to getting this right, but having one issue. Here's my code:

Código: [Seleccionar]
`if (stickx>0)             if (sticky<0)                  angle=90+atan2(sticky,stickx);             else                  angle=-90+atan2(sticky,stickx);             end         end         if (stickx<0)            if (sticky!=0)                 angle=180-atan2(sticky,stickx);            end         end`
(stickx and sticky refer to the axes of the analog stick)

The problem is, the second part of the code works fine. The ship points left, and at the precise angle that it's supposed to. In the first part of the code, the ship points opposite of where it's supposed to. In other words, when the ship points right and down, the ship is actually pointing up. The same happens when it points right and up... it points down instead. The rotation is backwards while the stick is pointing right. The calculations seem to be alright; I got out my scientific calculator and computed all of the equations necessary, based on what atan2 returns for each equation; hence the 90, -90, and 180-atan2. I cannot figure out, after three hours, why the right side rotation is backwards. Any math wizards here that can help?

The range of angles I get from the atan2 equations are top left: 90 degrees, middle left: 180 degrees, bottom left: -90 degrees, top right: 90 degrees, middle right: 0 degrees, bottom right: -90s degrees.
« última modificación: Enero 04, 2017, 07:42:49 am por FusekiGames »

#### panreyes

• Mensajes: 2125
• Karma: 71
##### Re:Corresponding analog stick state to angle of sprite
« Respuesta #1 en: Enero 04, 2017, 08:18:09 am »
Hello

I think you're looking for this:
Código: [Seleccionar]
`fget_angle(0,0,stickx,sticky);`

#### FusekiGames

• Newbie
• Mensajes: 4
• Karma: 0
##### Re:Corresponding analog stick state to angle of sprite
« Respuesta #2 en: Enero 04, 2017, 08:31:34 am »
Hello

I think you're looking for this:
Código: [Seleccionar]
`fget_angle(0,0,stickx,sticky);`

Yes it is, and I looked right past it. I guess that's another one I can add to the list of things that I've tried to make too complicated

Thanks very much for your help!