How to Make the bullet faster over time?

hello,

I want c# code to make object (ball) faster over time?

i have used this code but it failed

void a(){

transform.speed(0,9,0)

}

thanks,

If you want it to move faster and faster over time, the problem is that you’re setting the speed to always be 9. You also are not specific on whether you want to use physics, or transform properties to move your bullet.

Here’s how to move an object using transform.Translate. In this example you’ll press ‘F’ to increase speed. To have this speed increase happen over time, just use it in Update without having it inside of the if() statement.

using UnityEngine;
using System.Collections;

public class TranslateObject : MonoBehaviour
{
	float speed = 1.0f;
	
	void Update()
	{
		//Test - Press and Hold 'F' Key to increase speed
		if(Input.GetKey(KeyCode.F))
		{
			speed += 0.1f;
		}
		
		transform.Translate(transform.forward * speed * Time.deltaTime);
	}
}

Here’s how to move an object by using transform.position instead of translate.

using UnityEngine;
using System.Collections;

public class TranslateObject1 : MonoBehaviour
{
	float speed = 1.0f;
	
	void Update()
	{
		//Test - Press and Hold 'F' Key to increase speed
		if(Input.GetKey(KeyCode.F))
		{
			speed += 0.1f;
		}
		
		transform.position += transform.forward * speed * Time.deltaTime;
	}
}

And finally, how to move an object with ConstantForce.force

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(ConstantForce))]

public class TranslateObject1 : MonoBehaviour
{
	float speed = 1.0f;
	Vector3 force;
	
	void Awake()
	{
		//Another way to "Require" the component.
		if(!GetComponent<ConstantForce>())
			gameObject.AddComponent<ConstantForce>();
		//
		force = constantForce.force;
		rigidbody.useGravity = false;
	}
	
	void Update()
	{
		constantForce.force = force;
		//Test - Press and Hold 'F' Key to increase speed
		if(Input.GetKey(KeyCode.F))
		{
			speed += 0.1f;
		}
		
		force += transform.forward * speed * Time.deltaTime;
	}
}