Question by
connorwforman · Jul 09, 2018 at 10:02 PM ·
scripting problemrigidbody
Bullet instantiates but doesn't move forward?
My cannonball instantiates but just falls flat on the ground instead of moving forward. 'Is kinematic' is not checked, and the speed is set to 100, and the mass is 7.2 but still won't do anything.
public class CannonShoot : MonoBehaviour {
public Transform CannonballSpawn;
public float OriginalSpeed = 5.0f;
public Rigidbody Cannonball;
private void Update()
{
Cannonball = Cannonball.GetComponent<Rigidbody>();
if(Input.GetKeyDown(KeyCode.Space))
{
Instantiate(Cannonball, CannonballSpawn.transform.position, CannonballSpawn.transform.rotation);
Cannonball.velocity = transform.TransformDirection(CannonballSpawn.forward * OriginalSpeed);
}
}
}
Comment
Answer by binaryuniverse · Jul 10, 2018 at 01:17 AM
You shouldn't need to change between local and world. Try changing this line:
Cannonball.velocity = transform.TransformDirection(CannonballSpawn.forward * OriginalSpeed);
to this:
Cannonball.velocity = transform.forward * OriginalSpeed;
Also, though I suspect you only gave partial code and this is probably not an issue for you, just in case, check to make sure that you initialize CannonballSpawn.