2 registered members (TipmyPip, 1 invisible),
18,731
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Joystick problems.
#247453
01/20/09 23:36
01/20/09 23:36
|
Joined: May 2006
Posts: 27
BrockA
OP
Newbie
|
OP
Newbie
Joined: May 2006
Posts: 27
|
Heyy there.. I was wondering if somebody could take a quick look at my code and possibly explain what I'm doing wrong? Right now I'm trying to code movement of a Entity with a Playstation Joystick.. The problem is the joy_force.x, because it's only controlling the pan of the Entity in ONE direction. As you can imagine there is 4-DPad buttons.. Up,Down,Left, and Right. and It only moves to the right. I want to be able to move the entity to the left, and to the right. How would I go about fixing my code to make it work? Thanks for any help! -Brock while(1)
{
wait(1);
if(joy_force.y)
{
c_move (my, vector(6*time_step,0,0), nullvector, GLIDE);
wait (1);
}
if (joy_force.x)
{
my.pan += 8*time_step;
}
if (!joy_force.y)
{
idle_percent = (idle_percent +2*time_step)%100;
ent_animate(me,"stand",idle_percent,ANM_CYCLE);
}
else
{
ent_animate(me,"walk",walk_percent,ANM_CYCLE);
walk_percent += 10 * time_step;
}
if (joy_2 && joy_force.y)
{
ent_animate(me,"run",run_percent,ANM_CYCLE);
run_percent = 7* time_step;
}
}
|
|
|
Re: Joystick problems.
[Re: BrockA]
#247852
01/22/09 23:16
01/22/09 23:16
|
Joined: Aug 2005
Posts: 512 Bayern
Schmerzmittel
User
|
User
Joined: Aug 2005
Posts: 512
Bayern
|
Hiho.. i dont know if this work with C-Script. But you can define your keys like this:
var RIGHT, LEFT;
function CheckKeys()
{
RIGHT = (joy_force.y > 0);
LEFT = (joy_force.y < 0);
} Then you can use like this:
if(RIGHT - LEFT)
{
c_move (my, vector(6*time_step,0,0), nullvector, GLIDE);
}
Ah..and in your code you can leave the wait(1). In a if-decision you dont need a wait(1). Hope this helps. The code works for me in Lite-C. I hope in C-Script too. Greetings Schmerzmittel
A7 Com V7.80
|
|
|
Possible aswer
[Re: BrockA]
#248213
01/25/09 13:01
01/25/09 13:01
|
Joined: Apr 2006
Posts: 159 Latvija
Arrovs
Member
|
Member
Joined: Apr 2006
Posts: 159
Latvija
|
//First var virziens;//left and right //ad if you want more vars then need var smtg_else;
function kustiba//movement { while(1)//this is for example { //this code below you place in your code if(joy_force.y>0){virziens=6*time_step} if(joy_force.y<0){virziens=-6*time_step} //here you move in that direction now to which you press c_move(my,vector(virziens,0,0),nullvector,GLIDE); wait(1); } }
Arrovs once will publish game
|
|
|
Re: Possible aswer
[Re: BrockA]
#249233
02/01/09 10:33
02/01/09 10:33
|
Joined: Apr 2006
Posts: 159 Latvija
Arrovs
Member
|
Member
Joined: Apr 2006
Posts: 159
Latvija
|
nice to hear! If only need something - only ask!
Arrovs once will publish game
|
|
|
|