|
How to convert Joy_rot values to binary values like Joy_hat?
#442872
07/05/14 09:51
07/05/14 09:51
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
My game has a 4 directional dodge maneuver that I'm trying to map to the right analog stick. The problem is that the analog sticks return a range of values depending on how far down the player pushes them in any direction. I want my right analog stick to work like the 4-direcrional D-Pad. To dodge to the right for example, I have tried this
if(key_cur && my.state == 1 && Energy > 10){Energy -= 10; my.state = 2;} //Dodge Right
if((joy_rot.y=255) && my.state == 1 && Energy > 10){Energy -= 10; my.state = 2;} //Dodge Right
if(my.state == 2) //Dodge Right
{
while(joy_rot.y > 10)
wait(1);
joy_rot.y = 0;
dash += 8 * time_step;
my.animation += 2 * time_step;
ent_animate(me, "jump", my.animation, ANM_CYCLE);
c_move(me, vector(0, -dash*time_step, 0), nullvector, GLIDE | USE_POLYGON |IGNORE_PASSABLE);
if(dash > 59)
{dash = 0; my.animation = 0; my.state = 3;}
}
The keyboard controls work but I haven't been able to get the joystick controls right. Depending on which "where" clause I try, I'll either get the character dodging to the right over and over again once the right stick is flicked, or he'll dodge once and become unable to move afterwards, or he won't dodge at all.
|
|
|
Re: How to convert Joy_rot values to binary values like Joy_hat?
[Re: Superku]
#442926
07/05/14 23:31
07/05/14 23:31
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
"joy_rot.y=255" This is NOT a comparison, you assign a value there.
WOW! I can't believe I made such an obvious mistake! I know the difference so it's shameful that I didn't notice it while troubleshooting my code. Also, a direct == comparison didn't work, but using if(joy_rot.y > 192) works perfectly. It executes just once and I didn't have to refactor my code. Thanks a lot man, you're literally the second programmer on my team  One last major problem I've been struggling with for weeks, after which, I'll be quiet on these forums for a while: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=442919#Post442919
Last edited by tolu619; 07/06/14 02:10. Reason: Added link to other thread
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|