Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 12,709 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
calculating constant speed... need help! #284467
08/13/09 13:13
08/13/09 13:13
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
Hi,

I'm doing some flying game controlled by some hardware devices as input ( variable input like potentiometer). The hardware stuff works fine...but I'm just stucked with my game application side... To think/emulate it easily is that everytime a specific key press, for example a spacebar, would serve as input. The more you press/hold the spacebar, the player would move up, else it would move down.. but i'm not sure how to move it straight or the constant speed???

The variable input would serve as the input for the speed movement. Basically, the idea is like:
increasing speed = player move tilt up
decreasing speed = player move tilt down
constant speed = player moves straight (horizontal)

Here's my code snippet:
Code:
var varHWSpeed = 0;
var varPrevHWSpeed = 0;
var varAccel = 0;

action act_player()
{	  
   while(1)
   {		    	
     HandleMovement();
     HandleCamera();		
     wait(1);  
   }
}

function HandleMovement()
{			
   varHWSpeed = get_HWSpeed(); //get the actual speed in hw interface
   varHWSpeed /= 10; //divide by 10 shorter calculation; range is 0 to 48
	
   if(varPrevHWSpeed != varHWSpeed)
   {
     if(varPrevHWSpeed < varHWSpeed)
     {
	varAccel += 1 * time_step;
  	player.tilt += 5 * time_step;	
     }
     else
     {
	varAccel -= 1 * time_step;
  	player.tilt -= 5 * time_step;		
     }	
   }		  	  
 c_move(player,vector(varHWSpeed,0,varAccel),nullvector,IGNORE_PASSABLE | GLIDE); // move the player	
      		
   player.roll = clamp( (player.roll + mouse_force.x * time_step * 15), -50, 50 );	
   player.tilt = clamp( player.tilt, -30, 30 );
   player.pan = (player.pan-  player.roll*time_step*0.05);					
	
   varPrevHWSpeed = varHWSpeed;  //set prev speed equal now to current speed
	
   wait(1);
}



Any idea how I could calculate the constant speed? Or perhaps an average speed??

Hope someone could give me idea. Thanks

Re: calculating constant speed... need help! [Re: boyax] #284617
08/14/09 09:25
08/14/09 09:25
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
Anyone?


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

Gamestudio download | 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