Timing problem

Posted By: theDust

Timing problem - 02/25/09 00:48

Hellooo, I've made a little test arrangement:

You let a physical object, let's say a ball, jump with the space-key. When the ball is hitting the ground and space is pressed a force, i use phent_addvelcentral(ENTITY*,VECTOR* speed), will move the object. No problem so far.
You keep pressing space. Now you see, the jumps doesn't have a constant height. Sometimes the ball jumps right in the moment when he has touched the ground. And sometimes he sticks to the ground a few millisecs and makes a jump half of the height as the jump before.
The ball doesn't move and doesn't rotate, its only jumping. You can clearly see, something at the timing goes wrong eek

I've set fps_max = 60 and when i raise the "ph_fps_max_lock" the collision-detection gets a bit better, but its far from good. Any idea ?
Posted By: zwecklos

Re: Timing problem - 02/25/09 01:05

Hi there,
You could set up a timer which handles the amount of time a jump could happen.

In this way you can prevent that behaviour.
For example when you hit the space key, the timer starts to count, now you define how much time a jump may take. Just make sure that another jump only can happen when this timer has a certain amount.

You could handle timer-counting and reseting by traces, with a trace downward you always can find out if your ball/player is touching the ground or not.

hope this helps...

cheers
Posted By: theDust

Re: Timing problem - 02/25/09 11:47

Thx ! But later the object should jump across the world, with nonlinear jumps --> calculating the time of 1 jump would only work with linear jumps, always at the same position.
When the object is moving around while jumping its harder to spot that the timing is wrong, but it is wrong frown

Yes, c-trace is a nice thing, i use it already.

Sooo, a GS-master is needed ! smile
Posted By: Quad

Re: Timing problem - 02/25/09 12:00

upload your script/test app so we can get a inner look.
Posted By: theDust

Re: Timing problem - 02/25/09 12:40

Here the code :
Code:
#include <acknex.h>
#include <default.c>

ENTITY* pointer;
VECTOR global;
VECTOR check;
VECTOR jump;

var checkj = 0;

function main() 
{
	video_screen = 2;
	video_mode = 8;	
	mouse_mode = 1;	
   fps_max = 60;  
   wait(-1);
	level_load ("level1.wmb"); 
   ph_setgravity (vector(0, 0, -700));   
} 


action playerj() 
{
  pointer = my;
  my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); 
  phent_settype (pointer, PH_RIGID, PH_SPHERE); 
  phent_setmass (pointer, 1, PH_SPHERE);
  phent_setfriction (pointer, 500); 
  phent_setdamping (pointer, 50, 50); 
  phent_setelasticity (pointer, 0, 0);
  
  jump.x = 0; jump.y = 0; jump.z = 150;  

   while (1) {    
  	  global.x = my.x ;
  	  global.y = my.y ;
  	  global.z = my.z ;
  	  
  	  check.x =  my.x;
  	  check.y =  my.y;
  	  check.z =  my.z-23; //the height of the ball/2
  	   
     checkj = c_trace(global,check,USE_BOX);
     
     if(key_space && checkj != 0)
     {     
         phent_addvelcentral(pointer,jump);
     }
     wait (1); 
  }

}

And here the whole project, jump with space :
http://www.file-upload.net/download-1482643/testjump.rar.html
Be a bit patient, sometimes the weird timing needs a few jumps to get visible wink
Posted By: theDust

Re: Timing problem - 02/26/09 12:08

I have really no clue how to solve this, maybe i use c_trace wrong, but I think that's not causing the problem. Help would be great !
© 2024 lite-C Forums