Message Board
Message Board > Fenix / Bennu / Gemix / DIV > Analog controls |
May 29, 2010, 14:14 | |
Fuseki
Old Man 9 posts |
I'll preface this by stating that I'm using the port of Fenix to the Dreamcast (.84b)... I'm trying to wrap my head around a proper method of utilizing an analog stick on a gamepad, but everything I'm trying doesn't seem to achieve the desired outcome. Here's what I'm trying to do: 1. When moving the stick in a specific direction, the object will rotate towards that direction then stop when it reaches the direction pointed towards by the stick (i.e. if the stick is pointed down-right, the object rotates towards down-right then stops when the angle is reached). 2. When moving the stick in a specific direction, the playfield will also move towards the angle that the object is turning to (this is using a scrolling playfield, with the object affixed in the center), sort of like a constant "thrust." 3. The movement stops when the stick is released. I'm trying to think of the name of a game that utilizes this movement, but one escapes me at the moment. Basically, the player is able to move the playfield by circling the analog stick, while rotating his ship. This is my controls process with variables, called within a loop: Code: process controls(); begin p1joy=select_joy(0); stickx=get_joy_position(0); sticky=get_joy_position(1); padstart=get_joy_button(3); pada=get_joy_button(2); padb=get_joy_button(1); padx=get_joy_button(6); pady=get_joy_button(5); end I've been able to achieve either 1 or 2, but not both. Any help or suggestions would be greatly appreciated. Thanks!! ____________ Fuseki Games- classic-style games for the Dreamcast http://www.fusekigames.com |
# |
May 29, 2010, 15:38 | |
Fuseki
Old Man 9 posts |
Ahhh... after sitting and trying to work it out, I think I'll just add a thrust control. It seems to me that using a button to thrust would give the player more control. However, this problem still bugs me and I'll continue to try to work it out. I'm more concerned with figuring out how to translate the analog stick values to angles so I can use the whole stick rather than just simple left and right rotation (angle-=10000, angle+=10000, respectively). I'd be cool to point the stick to the upper-right (and all the other directions) and have the player rotate to that angle at a predetermined speed and stop. Suggestions are still welcome and highly appreciated. Thanks! [Edited on May 29, 2010 by Fuseki] ____________ Fuseki Games- classic-style games for the Dreamcast http://www.fusekigames.com |
# |
June 1, 2010, 10:10 | |
Dennis
どこかにいる 2092 posts |
Quoting Fuseki: Thanks! You're welcome. ____________ Kwakkel |
# |
June 3, 2010, 00:37 | |
DTM
Earthling! 821 posts |
So you have an x and y from the joystick position. You ought to be able to use trigonometry to get the angle. Something like angle = atan(sticky / stickx) maybe you'll have to tweak it a bit though, perhaps adding some constant angle, swapping or negating x or y... Trial and error is usually my approach to move the playfield is surely just adding or subtracting stickx and sticky to/from the playfield x,y coordinates (multiplied by a speed factor) each frame? ____________ :o |
# |
June 3, 2010, 15:14 | |
Fuseki
Old Man 9 posts |
Quoting DTM: So you have an x and y from the joystick position. You ought to be able to use trigonometry to get the angle. Something like angle = atan(sticky / stickx) maybe you'll have to tweak it a bit though, perhaps adding some constant angle, swapping or negating x or y... Trial and error is usually my approach to move the playfield is surely just adding or subtracting stickx and sticky to/from the playfield x,y coordinates (multiplied by a speed factor) each frame? Unfortunately, my math knowledge is lacking. I did some research into using the x and y values from the stick (they're typical; -128 to 128 for both) and found some info about atan, but the info was either in C, C++, or java (all of which I am lacking knowledge in). And being a 40 year old guy, I've pretty much forgotten everything I learned in math For moving the playfield, I'm just using a scroll region and advance(), and using angle() to turn the ship, i.e. Code: process playership(); private ad=0; begin graph=4; pointertoflag(); loop; quit(); controls(); frame; playerx=x; playery=y; scroll.camera=id; ctype=c_scroll; advance(ad); if (energy>0) if (key(_alt)); if (ad<25); ad++; energy--; end end end if (not key(_alt)); if (ad>0); ad--; end end if (key(_left) or stickx<0); angle+=20000; end if (key(_right) or stickx>0); angle-=20000; end end end The alt key corresponds to the B button on the Dreamcast pad. Thanks for the info. I'll play around and see what I can come up with. (I really should move that frame command...) [Edited on June 5, 2010 by Fuseki] ____________ Fuseki Games- classic-style games for the Dreamcast http://www.fusekigames.com |
# |
June 8, 2010, 23:41 | |
DTM
Earthling! 821 posts |
I think the atan is basically the same as in C++ etc, except uses degrees rather than radians. http://xzist.org/temp/fenix_ma … mands.atan.html ____________ :o |
# |
June 21, 2010, 18:37 | |
Fuseki
Old Man 9 posts |
Quoting DTM: I think the atan is basically the same as in C++ etc, except uses degrees rather than radians. http://xzist.org/temp/fenix_ma … mands.atan.html As soon as I figure it out, I'll post the code here. I'm somewhat liking the thrust button scheme right now, but this problem is one I'd like to work out so I can fix the analog control problems in my LAST game... ____________ Fuseki Games- classic-style games for the Dreamcast http://www.fusekigames.com |
# |
Message Board > Fenix / Bennu / Gemix / DIV > Analog controls