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