smooth move with joypad

BlitzMax Forums/BlitzMax Programming/smooth move with joypad

hub(Posted 2011) [#1]
Hi !
No problem to smooth move my ship with mouse (rockout model) and keyboard. But with the joypad i can't code anything right.

I want smoothly move my ship. some acceleraten and decelerate.

Hope you understand my problem ! Not smooth with joypad, see my poor code...

Please help me to correct this !

many thanks !




see the video with mouse control : http://www.youtube.com/watch?v=tJD_kSeZYVE&feature=player_embedded

Last edited 2011


H&K(Posted 2011) [#2]
you have messed up when you need <-0.5


hub(Posted 2011) [#3]
?


H&K(Posted 2011) [#4]
If JoyX(NumPad) > 0.5 And JoyY(NumPad) > 0.5 Then
xdir = 1
ydir = 1
bBoutonAppuye = True
Else
If JoyX(NumPad) < 0.5 And JoyY(NumPad) < 0.5 Then
xdir = -1
ydir = -1
bBoutonAppuye = True
Else
etc


hub(Posted 2011) [#5]
it seems that i've not pb with this code part... work well with two gamepads. i just want have some idea to improve next the code to compute the displacement.


H&K(Posted 2011) [#6]
the code you have is sometimes checking for <-0.5, which is ok, cos you are leaving a dead zone. -0.5 to 0.5

However you have forgotten the minus sign sometimes, so you then go left (or down) (or left and down) when your are pressing left AND when you are in the dead zone


hub(Posted 2011) [#7]
It seems i never be inside the dead zone with my pads ? many thanks for your help but i don't understand exactly where is the problem and correct it. If i correct this i could have a smooth move ? player already correctly move to the eight directions here.


Jesse(Posted 2011) [#8]
I see the same problem as H&K.
I also see a problem with the joystick center x and y. Analog joystick rarely give exact same value when the joystick return to the center thats why you have to assign a dead Zone. I think that's what is giving you the most problems. thats just a guess as I can't tell much from the video.

I was also wondering why so many if statements? Why not just this?:
xdir = 0
ydir = 0
bBoutonAppuye = False
if JoyX(NumPad) <-0.5 then xdir = -1; bBoutonAppuye = True
if JoyY(NumPad) <-0.5 then ydir = -1; bBoutonAppuye = True
if JoyX(NumPad) > 0.5 then xdir = 1; bBoutonAppuye = True
if JoyY(NumPad) > 0.5 then ydir = 1; bBoutonAppuye = True


Last edited 2011

Last edited 2011


col(Posted 2011) [#9]
Hiya,

H&K means this :-

Where you have code like :-

If JoyX(NumPad) < 0.5

It should be

If JoyX(NumPad) < -0.5 'note the minus sign!!


hub(Posted 2011) [#10]
ok to control the direction, any idea to have a smooth movement ?


H&K(Posted 2011) [#11]
we think that you should now have smooth movement.

@Jesse the video is what he wants

The main question is, from the video you have analogue movement (Well it looks so, and that's normal mouse movement)
However your code is to get digital Movement

{Analogue the more you move it left the greater LEFT per second you get}
[Digital once it reaches Left, its at maximum left ie either stopped or max]


GfK(Posted 2011) [#12]
the code you have is sometimes checking for <-0.5, which is ok, cos you are leaving a dead zone. -0.5 to 0.5
Leaving a dead zone that takes up half of the joypad's movement might work fine on a digital pad, but on an analog one it is going to be awful. The player character just won't respond until you move the controller at least half way between the centre and maximum on the x/y axis.

A dead zone of 0.01 would be more suitable.


hub(Posted 2011) [#13]
ok i've added the minus sign to correct my mistake. In fact i'm searching a way to have the same effect that i've with the mouse and the keyboard.

The ship gradually accelerate. and when you release the key (or the direction button with the pad) the ship speed slowly decrease.



sorry for french names inside the code.


hub(Posted 2011) [#14]
see the rockout.bmx sample. i want this for the joypad !


hub(Posted 2011) [#15]
now i change also the code to set the dead zone to 0.01. i replace 0.5 by 0.01

note :

' when the game start i've already this :
gCentre_joypad_un_X#   = JoyX#(0)
gCentre_joypad_un_Y#   = JoyY#(0)

' and next
Centre_joyX# = gCentre_joypad_un_x#
Centre_joyY# = gCentre_joypad_un_y#



hub(Posted 2011) [#16]
updated code :


Last edited 2011


Pete Carter(Posted 2011) [#17]
You could make a x and y speed and a target x and y speed. with no direction pressed the target speed would be 0. and when you press the stick in a direction it would set the target speed to 1. Every loop you would make it add 0.1 to the speed until it matchs the target.

Just an idea, could make it feel a bit laggy.


H&K(Posted 2011) [#18]
Stop giving him advice about how to it, unless that advice is do it exactly the way you did it for keyboard.
I know you think its all helpful, but apparently he has Keyboard code that works, AND Mouse code that works.
So eiher there is a bug in bmAX Joypad code, or in Hubs code


Ignore what GFK said about the dead zone, (Hes right, but as you are immeadiatly unanalogueing the result, it isnt important)

@GFK, doesnt matter what his deadzone is hes makeing the result -1,0,1 anyway (and his code is so c64 rather than BBC that I doubt he has an analogue Stick)

@Hub play the game on keyboard, if it works change one key at a time to a joypad key

Last edited 2011


hub(Posted 2011) [#19]
i post here a sample if you want try to find a method

removed.

Last edited 2011


hub(Posted 2011) [#20]
i'm searching... This seems to me ok. Could you try this ?


Last edited 2011


Jesse(Posted 2011) [#21]
what is wrong with what I posted above?:



you don't even need the bJoypad_action variable

Last edited 2011

Last edited 2011


hub(Posted 2011) [#22]
.

It seems Jesse code works fine. In fact i've a problem _inside_ my game.

Last edited 2011


hub(Posted 2011) [#23]
Sorry for this. And many thanks to you for your help ! this is a big project so sometimes it's difficult to find what's wrong and you panic . You add silly imbricated if and nasty code !

Last edited 2011


Jesse(Posted 2011) [#24]

You add silly imbricated if and nasty code !


I been there. Specially when I get frustrated. it's the hardest time to debug. I find that giving myself a brake helps.


hub(Posted 2011) [#25]
yes i was inside the deadzone lol !