|
Collision and Jump code
#130410
05/17/07 15:00
05/17/07 15:00
|
Joined: May 2007
Posts: 10 Itajaí - SC - Brazil
Sputnicker
OP
Newbie
|
OP
Newbie
Joined: May 2007
Posts: 10
Itajaí - SC - Brazil
|
Hi people, its my first post on this forum. Sorry about my poor english language... ^^ I'm developing a game with no templates, and I have some problems with the colision and the jump codes... The colision problem is: I can move ok, but when I'm moving sometimes I can go inside of objects... and can't move back because its colided... Other bug in colision is that when I go to a wall, if I stay much close to this the player goes up...
The jump problem is: how can I do that? I'm newbie in the gameprogramming, and no know how it works... need I deactivate de gravity while I'm jumping?
Here is the code of my player:
function andarfc { var snd; if tocando == 0 { snd=snd_play(andarsnd,70,0); tocando = 1; wait(16); snd_stop(snd); tocando = 0; } }
action Playerprinc { var move_var; //We're going to use this as our move vector (X,Y,Z) var tempmypos; player = me; my.invisible = on; while(1) //while the player object exists { move_var.x = 0; //resets them all back to 0 move_var.y = 0; //if we don't do thist hen the variables will addup move_var.z = 0; //making the player move faster and faster with no stopping if movimento == 1 { camera.x = player.x; camera.y = player.y; camera.z = player.z + 100; camera.pan = player.pan; if fase3cn == 0 {player.pan -= sensi*mouse_force.x; camera.tilt += sensi*mouse_force.y;} if camera.tilt > 90 {camera.tilt = 90;} if camera.tilt < -90 {camera.tilt = -90;} } tempmypos.x = my.x; tempmypos.y = my.y; //tempmypos.z = my.z; colissssao = c_trace(tempmypos,move_var,ignore_me + ignore_you + ignore_passents + ignore_passable); vec_set(temp,my.x); //copies the second vector to the first temp.z -= 8000; //lets make the trace point way way below us trace_mode = ignore_me+ignore_sprites+ignore_models+use_box; //see manual result = trace(my.x,temp); /* if(result > 5) //if from my pos to temp is greater than 5 { move_var.z -= gravidade; }*/ //fall speed of 20 (higher number, faster falling speed) if(result > 100) { show_health -= 1; wait(1);} if(result <= 0) //if from my pos to temp is less than or equal to 0 { move_var.z += 2; } //not touching the floor but extremely close
if(key_w == on) && (show_health > 0) && (fase3cn == 0) //if we press the up arrow key { if (key_shift == on) { move_var.x = 8 + fase3; //give the X parameter a value of 4 andarfc(); } else { move_var.x = 4 + fase3; //give the X parameter a value of 4 andarfc(); } } if(key_s == on) && (show_health > 0) && (fase3cn == 0) //if we press the down arrow key { if (key_shift == on) { move_var.x = -6 - fase3; //give the X parameter a value of 4 andarfc(); } else { move_var.x = -2 - fase3; //give the X parameter a value of 4 andarfc(); } } if(key_a == on) && (show_health > 0) && (fase3cn == 0) //if we press the left arrow key { move_var.y = 4 + fase3; //add to the pan value andarfc(); } if(key_d == on) && (show_health > 0) && (fase3cn == 0) //if we press the right arrow key { move_var.y = -4 - fase3; //subtract the pan value andarfc(); } if(key_space == on) && (pulando == 0) && (show_health > 0) && (fase3cn == 0) //if we press the right arrow key { wait(1); } if (show_health <= 0) { wait(1); } move_friction = 0; c_move(me,move_var,nullvector,IGNORE_PASSABLE+GLIDE+USE_BOX); wait(1); } }
Last edited by Sputnicker; 05/17/07 15:03.
|
|
|
Re: Collision and Jump code
[Re: Sputnicker]
#130412
05/17/07 19:23
05/17/07 19:23
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
User
|
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
player.z += is when player is in passable //even if you not set it, thats the engine code Try to increase bounding box setting around entitys by: my.fat =on; my.narrow = off; or set c_setminmax(me);
Last edited by tompo; 05/17/07 19:24.
Never say never.
|
|
|
Re: Collision and Jump code
[Re: Sputnicker]
#130414
05/17/07 19:46
05/17/07 19:46
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
User
|
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
Quote:
When I move to a wall the c_trace think that the top of the wall is the floor and lift me up...
not exacly because you trace -800 so you trace down not ahead
this will keep your entity always on the ground Code:
function gravity { vec_set(temp, my.x); temp.z -= 5000; trace_mode = IGNORE_ME + ignore_models + IGNORE_PASSABLE + IGNORE_SPRITES + use_box + scan_texture; result = trace (my.x, temp); my.z -= result; }
you may of course cut ignore_models if you want
Last edited by tompo; 05/17/07 19:50.
Never say never.
|
|
|
Re: Collision and Jump code
[Re: xXxGuitar511]
#130417
05/28/07 17:36
05/28/07 17:36
|
Joined: Nov 2006
Posts: 141 South Africa
quasarchangel
Member
|
Member
Joined: Nov 2006
Posts: 141
South Africa
|
/* if(result > 5) //if from my pos to temp is greater than 5 { move_var.z -= gravidade; }*/ //fall speed of 20 (higher number, faster falling speed)
Why is this commented out?
Try changing the following into the blue code below.
/* if(result > 5) //if from my pos to temp is greater than 5 { move_var.z -= gravidade; }*/ //fall speed of 20 (higher number, faster falling speed) if(result > 100) { show_health -= 1; wait(1);} if(result <= 0) //if from my pos to temp is less than or equal to 0 { move_var.z += 2; } //not touching the floor but extremely close
if(result > 5) //if from my pos to temp is greater than 5 { move_var.z = -5; } //fall speed of 20 (higher number, faster falling speed) //if(result > 100) { show_health -= 1; wait(1);} if(result < 5) //if from my pos to temp is less than or equal to 0 { move_var.z = -result; } //not touching the floor but extremely close
Hope it works.
Whats the "if(result > 100) { show_health -= 1; wait(1);}" for? Why "wait(1);" after it?
God DID give us a manual on how to change this world...
|
|
|
|