|
|
movement problems
#327223
06/05/10 10:18
06/05/10 10:18
|
Joined: Jan 2010
Posts: 20
FraK
OP
Newbie
|
OP
Newbie
Joined: Jan 2010
Posts: 20
|
Well, I wanted to start programming a little game, in which you can move around with the mouse. The mouse_force.y is responsible for the speed and mouse_force.x for the direction, but in fact it doesn't work! Here's my code:
VECTOR boden; var speed_down = 0; var dist_down = 0; var dist_ahead = 0;
action Spieler() { player = my;
c_setminmax(my); wait(1);
camera_pos(); set(my,POLYGON); vec_for_min(boden,me);
my.pan += 5 * mouse_force.x * time_step; if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME |IGNORE_PASSABLE | USE_BOX) > 0) { dist_down = my.z + boden.z - target.z; } else { dist_down = 0; } if(dist_down>0) { dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1)); } else { speed_down = 0; }
var dist_ahead = 5* mouse_force.y* time_step; c_move(me,vector(dist_ahead,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE| GLIDE); }
|
|
|
Re: movement problems
[Re: FraK]
#327229
06/05/10 10:57
06/05/10 10:57
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
You don't have a while loop, now the engine 'looks into' the function only once, but it has to 'look into it' again and again to apply the values of the mouse_force each time anew.
VECTOR boden; var speed_down = 0; var dist_down = 0; var dist_ahead = 0;
action Spieler() { player = my;
c_setminmax(my); wait(1);
camera_pos();
set(my,POLYGON);
while(1) {
vec_for_min(boden,me);
my.pan += 5 * mouse_force.x * time_step;
if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME |IGNORE_PASSABLE | USE_BOX) > 0) {
dist_down = my.z + boden.z - target.z; }
else { dist_down = 0;
}
if(dist_down>0) { dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1)); } else { speed_down = 0; }
var dist_ahead = 5* mouse_force.y* time_step; c_move(me,vector(dist_ahead,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE| GLIDE); wait(1); } }
|
|
|
Re: movement problems
[Re: Pappenheimer]
#327231
06/05/10 11:25
06/05/10 11:25
|
Joined: Jan 2010
Posts: 20
FraK
OP
Newbie
|
OP
Newbie
Joined: Jan 2010
Posts: 20
|
thanx a lot Pappenheimer for the response! It finally works!! But I have one more question:(I'm not sure if I'm supposed to create a new thread) I need a simple ball-physics script: including bouncing, rolling...
There's mine, it works somehow, the movement stucks and the ball is bouncing at one point as crazy!! here's my script: function physics() { phent_settype(my, PH_RIGID, PH_SPHERE); phent_setmass(my, 0.1, PH_SPHERE); phent_setfriction(my, 5); phent_setdamping(my,10, 10); phent_setelasticity(my, 1, 0); temp.x = 0; temp.y = 0; temp.z = -380; ph_setgravity(temp); phent_setmaxspeed (my, 1000, 5); }
function reset_physics() { phent_settype(player, 0, 0);
phent_settype(player, PH_RIGID, PH_SPHERE); phent_setmass(player, 0.1, PH_SPHERE); phent_setfriction(player, 5); phent_setdamping(player,0, 50); phent_setelasticity(player, 10, 0); temp.x = 0; temp.y = 0; temp.z = -380; ph_setgravity(temp); phent_setmaxspeed (player, 1000, 10); }
Last edited by FraK; 06/05/10 11:26.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|