I want to increase speed every frame whilst a button is held down. Sounds simple? Here's my code...
var shipSpeed = 0.0;
var increase = 10.0;
function Update () {
var horiz : float = Input.GetAxis("Horizontal");
rigidbody.AddTorque (Vector3(0,horiz,0) * Time.deltaTime * 30);
var vert : float = Input.GetAxis("Vertical");
rigidbody.AddTorque(Vector3(0,0,vert) * Time.deltaTime *30);
rigidbody.AddForce (Vector3(shipSpeed,0,0) *Time.deltaTime);
if(Input.GetButton("Jump")){
shipSpeed += increase * Time.deltaTime;
}
}
here is the problem ... it requires a new press every time. How can I solve this issue?
Hey!
I noticed that the rigidbody could not spin because the mass was to high, so if it dose not hurt your gameplay. Turn it down.
Script:
var shipSpeed = 0.0;
var increase = 10.0;
@script RequireComponent(Rigidbody)
function Update ()
{
rigidbody.mass = 0.1;
var horizontalSpeed = Input.GetAxis("Horizontal");
var verticalSpeed = Input.GetAxis("Vertical");
if(Input.GetButton("Jump"))
{
shipSpeed += increase * Time.deltaTime;
}
rigidbody.AddTorque(Vector3(0,horizontalSpeed,verticalSpeed) * 10);
rigidbody.AddForce (Vector3(shipSpeed,0,0));
}
I cleaned your script up a bit. But as said the only problem I could find was the mass of the rigidbody.