|
c_move and joy_force
#159537
10/08/07 01:20
10/08/07 01:20
|
Joined: Mar 2005
Posts: 134
jeffmorris
OP
Member
|
OP
Member
Joined: Mar 2005
Posts: 134
|
In the Lite-C Workshop 15 tutorial, you learn how to write code to control the camera using the joystick. In the Lite-C Workshop 18 tutorial, you learn how to write code to control the car using the keyboard. I modified the code so that I can move the car forward and backward using the keyboard. How do I control the car using joystick? Code:
action my_car() { while (1) { if (key_a && key_cuu) my.pan += 3*time_step; if (key_s && key_cuu) my.pan -= 3*time_step; if (key_a && key_cud) my.pan -= 3*time_step; if (key_s && key_cud) my.pan += 3*time_step; if (key_cuu) c_move (my, vector(15*time_step, 0, 0), nullvector, GLIDE); if (key_cud) c_move (my, vector(-15*time_step, 0, 0), nullvector, GLIDE); wait (1); } }
|
|
|
Re: c_move and joy_force
[Re: jeffmorris]
#159538
10/09/07 11:14
10/09/07 11:14
|
Joined: Mar 2005
Posts: 134
jeffmorris
OP
Member
|
OP
Member
Joined: Mar 2005
Posts: 134
|
I'm not sure if this is the right way to use c_move and joy_force commands to move the car. Is it possible to attach the camera to the car and move them together? Code:
action my_car() { while (1) { if (joy_force.y>0) my.pan -= joy_force.x*time_step; if (joy_force.y<0) my.pan += joy_force.x*time_step; if (joy_force.y>0) c_move (my, vector(15*time_step, 0, 0), nullvector, GLIDE); if (joy_force.y<0) c_move (my, vector(-15*time_step, 0, 0), nullvector, GLIDE); wait (1); } }
|
|
|
Re: c_move and joy_force
[Re: jeffmorris]
#159539
10/09/07 16:22
10/09/07 16:22
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
For joystick control, you may try the following code : Code:
var speed = 5; // play with 5 var jForce; action my_car() { while(1) { jForce = (joy_6 - joy_5); // move forward and backward c_move(my,vector((joy_6-joy_5)*speed*time_step,0,0),nullvector,GLIDE); // turn left and right c_rotate(my,vector(-joy_force.x*time_step*jForce,0,0),USE_AXIS);
// follow cam vec_set(camera.x,vector(-200,0,40)); // play with the vec position vec_rotate(camera.x,my.pan); vec_add(camera.x,my.x); //camera.pan += 0.2 * ang (my.pan - camera.pan) * time_step; // line A vec_set(camera.pan,my.pan); // line B
wait(1); } }
If you want a little bit camera lag uncomment line A and comment out line B. My joystick may not the same as yours, try to modify those joy_???? youself. Have fun!
|
|
|
Re: c_move and joy_force
[Re: jeffmorris]
#159543
10/12/07 13:55
10/12/07 13:55
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
Maybe this thread could help.
|
|
|
|