Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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), 609 guests, and 3 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
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 | 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