In the following code there is a delay between pressing the horizontal axis keys (a, d and the arrow keys) and the value changing that is not apparent with the key that does “thrust” (ctrl).
Can anyone tell me how to remove the keyboard delay?
Ta,
Rich.
var xThrustAdd = 25.0;
var xThrustMax = 50.0;
var yThrustAdd = 25.0;
var yThrustMax = 50.0;
var grounded = false;
var gravity = -9.8;
private var velocity = Vector3.zero;
// this is for the Character Controller
var controller : CharacterController;
controller = GetComponent(CharacterController);
function Update ()
{
if (grounded) velocity.y = 0;
if (Input.GetButton("Thrust"))
{
velocity.y += yThrustAdd * Time.deltaTime;
}
if (velocity.y > yThrustMax) velocity.y = yThrustMax;
velocity.y += gravity * Time.deltaTime; // add gravity
if (Input.GetAxis("Horizontal") == 1)
{
velocity.x += xThrustAdd * Time.deltaTime;
}
else if (Input.GetAxis("Horizontal") == -1)
{
velocity.x -= xThrustAdd * Time.deltaTime;
}
else
{
velocity.x /= 1.2;
}
if (velocity.x < -xThrustMax) velocity.x = -xThrustMax;
if (velocity.x > xThrustMax) velocity.x = xThrustMax;
print(velocity.x);
var flags = controller.Move(velocity * Time.deltaTime);
grounded = ((flags CollisionFlags.CollidedBelow) != 0 );
// controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed);
}