I have an object that I want to give a forward speed when the game starts. The forward speed needs to increase every 5 seconds. I tried everything, but no joy.
var speed : float = 5.0;
var increaseAmount : int = 5;
InvokeRepeating("IncreaseSpeed", 2, 2);
function IncreaseSpeed ()
{
speed += increaseAmount;
}
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime);
}
This is the script I found, but it’s not working. Someone who can help me please?
Thanks in advance
Just replace Rotate with Translate, for instance:
function Update(){
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
iSpy
3
well i did same thing just with buttons for example w increases object speed and s decrease it
`
public Transform mover;
public float maxSpeed = 0.1f;
public float curentSpeed = 0f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(Input.GetKey(KeyCode.W))
{
adjustCurentSpeed(+0.001f);
}
if(Input.GetKey(KeyCode.S))
{
adjustCurentSpeed(-0.001f);
}
mover.transform.Translate(0, 0, curentSpeed);
}
public void adjustCurentSpeed(float adj)
{
curentSpeed += adj;
if(curentSpeed <=0f)
{
curentSpeed = 0f; // if speed goes below 1 it stays 0, doesnt go negative
}
if (curentSpeed > maxSpeed)
{
curentSpeed = maxSpeed; // curent speed never goes over max speed
}
if (maxSpeed < 0.1f)
{
maxSpeed = 0.1f;
}
}
`
you can just edit it to auto increase it over time without key input, hope it helps.