Instead of using AddForce to move the bullet when it’s created is there a way to set its speed, as in spawn it and make it move so and so meters per second forward from its spawn location?
void HandleActionInput()
{
if(Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Rigidbody bullet;
bullet = Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody;
bullet.AddForce(bulletSpawn.forward * 4000);
}
}
Sure, if you insist on using physics, then instead of calling AddForce, just assign the .velocity that you want it to have.
When you decide physics is more trouble than it’s worth, then just make a little movement script that has a public Velocity component, and set that. Then the script will transform.position += velocity * Time.deltaTime on each Update.
2 Likes
Juse use the constant force component on your bullet prefab, sets its velocity there, than it will start moving once you instantiate it.
if you set a value on the relative forces z axis, it will apply a constant velocity to the object along the object’s forward vector.
What if i turned off the gravity on its rigidbody and set the ForceMode to Velocity change? Would the value used to multiply its forward vector become its velocity? As in a value of 500 would make it move 500 m/s?
This is for a space sim by the way.
void HandleActionInput()
{
if(Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Rigidbody bullet;
bullet = Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody;
bullet.AddForce(bulletSpawn.forward * 500, ForceMode.VelocityChange);
}
}
1 Like
I’m not sure… if you want a specific velocity, you should just assign that velocity.