Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Gravity for player #417354
02/11/13 21:03
02/11/13 21:03
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

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):
Code:
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 Offline
User
Carlos3DGS  Offline
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:
Code:
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


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Gravity for player [Re: Carlos3DGS] #417419
02/12/13 14:42
02/12/13 14:42
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
Thanks for your reply! The problem with this code is that when the gravity is a high value the player is constantly pulled to te ground and can't walk stairs / step over small obstacles anymore.

If the gravity is a low value, the player doens't fall fast enough to make it look realistic...any ideas?

Re: Gravity for player [Re: Toon] #417421
02/12/13 14:57
02/12/13 14:57
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
You can use physX or apply gravity only if player is in air

Re: Gravity for player [Re: Toon] #417422
02/12/13 15:01
02/12/13 15:01
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
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":

Code:
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:

Code:
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#Post416746

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=417189#Post417189

If 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.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1