Collision and Jump code

Posted By: Sputnicker

Collision and Jump code - 05/17/07 15:00

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);
}
}
Posted By: Sputnicker

Re: Collision and Jump code - 05/17/07 19:08

About the collision problem:
When I go to the feet of an house, the player "lift up" in the wall and go to the ceiling ^^
Posted By: tompo

Re: Collision and Jump code - 05/17/07 19:23

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);
Posted By: Sputnicker

Re: Collision and Jump code - 05/17/07 19:42

my.fat =on; my.narrow = off;
It doesnt work... the player is aways going up...

c_setminmax(me);
This give a error while run game...

The problen is here:
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

When I move to a wall the c_trace think that the top of the wall is the floor and lift me up...
I need a function to not colide at all the player to the wall... ^^

I have no idea of how to do it... ^^
Posted By: tompo

Re: Collision and Jump code - 05/17/07 19:46

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

Posted By: Sputnicker

Re: Collision and Jump code - 05/17/07 22:45

the same problem... Tompo... You have MSN? I'm thinking in rewrite the player code...
Thanks for the help!
Posted By: xXxGuitar511

Re: Collision and Jump code - 05/28/07 16:42

Don't use use_box in your trace to the ground.
Posted By: quasarchangel

Re: Collision and Jump code - 05/28/07 17:36

/* 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?
Posted By: Nems

Re: Collision and Jump code - 05/28/07 18:25

var move_min_z = 0; is what you are looking for, example set to 0, actor will climb any angle.
Set to 4 or 6, restrain to 40 to 60 degrees respectivly but it depends on the models size and where the origin is set.

refer to manual for more info.
© 2024 lite-C Forums