1 registered members (AndrewAMD),
1,310
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Gravity for player
#417354
02/11/13 21:03
02/11/13 21:03
|
Joined: Nov 2003
Posts: 433 The Netherlands
Toon
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2003
Posts: 433
The Netherlands
|
hey, I'm trying to give player simple, yet effective gravity. This is what I have so far (in my real code I defined all variables and skills off course):
my.eflags |= FAT | NARROW;
while(1){
//trace down for gravity
floor_dist = c_trace(my.x,vector(my.x,my.y,my.z-1280),IGNORE_ME|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_MODELS|IGNORE_SPRITES|USE_BOX);
if(floor_dist<=4){
my.move_vec_z = 0;
}else{
my.move_vec_z = -((floor_dist/8)+4);
}
my.move_vec_z = clamp(my.move_vec_z,-24,0);
c_move(me,vector(my.move_vec_x,my.move_vec_y,0),vector(0,0,my.move_vec_z),IGNORE_ME|IGNORE_PASSABLE|GLIDE);
wait(1);
}
The problem is with sloping sections. When I go up it's all fine, but when i'm going down it kind of stutters (because of the continuous trace down/gravity down). Can someone tell me how to fix this without getting a big workaround code and all. (strairs by te way work just fine to and in main i call move_min_z = -1;) Thanks.
|
|
|
Re: Gravity for player
[Re: Toon]
#417361
02/11/13 22:04
02/11/13 22:04
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
User
|
User
Joined: Oct 2008
Posts: 513
|
the stuttering probably comes from the floor_dist=c_trace and if(floor_dist<=4) Your gravity probably takes you closer than 4 from the floor, so while the slope is still less than 4 you dont go down, until enough slope has been passed for it to be >4 again... I would recomment removing that c_trace and the whole if/else part... along with the clamp I would just go with the following:
while(1)
{
c_move(me,vector(my.move_vec_x,my.move_vec_y,my.move_vec_z),nullvector,IGNORE_ME|IGNORE_PASSABLE|GLIDE);
wait(1);
}
just decide on a value and set it for your gravity once in your code somewhere before this
|
|
|
Re: Gravity for player
[Re: Toon]
#417422
02/12/13 15:01
02/12/13 15:01
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
User
|
User
Joined: Oct 2008
Posts: 513
|
Keeping the move code as in the example above but adding the c_trace after to ensure a minimum value should fix that problem while avoiding "stuttering":
while(1)
{
c_move(me,vector(my.move_vec_x,my.move_vec_y,my.move_vec_z),nullvector,IGNORE_ME|IGNORE_PASSABLE|GLIDE);
floor_dist = c_trace(my.x,vector(my.x,my.y,my.z-1280),IGNORE_ME|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_MODELS|IGNORE_SPRITES|USE_BOX);
if(floor_dist<4)
{
my.z = hit.z+4;
}
wait(1);
}
EDIT: If that code still gives you problems to move, just separate the gravity movement from the normal movement in two different steps (with player movement first) so one does not effect the other like this:
while(1)
{
//First Character Movement
c_move(me,vector(my.move_vec_x,my.move_vec_y,0),nullvector,IGNORE_ME|IGNORE_PASSABLE|GLIDE);
//Second Gravity Movement
c_move(me,nullvector,vector(0,0,my.move_vec_z),IGNORE_ME|IGNORE_PASSABLE|GLIDE);
//Get distance to floor
floor_dist = c_trace(my.x,vector(my.x,my.y,my.z-1280),IGNORE_ME|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_MODELS|IGNORE_SPRITES|USE_BOX);
//force a constant minumum distance to allow walking up, but avoid "stuttering"
if(floor_dist<4)
{
my.z = hit.z+4;
}
wait(1);
}
EDIT2: Also, I am not sure if you are using time_step with your "move_vec_x/y/z". If you are planning on running the game on different computers other than the one you are using to program whith, your game will have problems at different framereates. Here are a couple of recent threads that can help you out getting started with time_step: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=416746#Post416746http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=417189#Post417189If you have any problems with time_step I will probably check this thread again this evening or tomorrow.
Last edited by Carlos3DGS; 02/12/13 15:22.
|
|
|
|