- Home /
Bullet movement from guns rotation
I'm attempting to instantiate a bullet prefab and apply a force to it based on the guns rotation. Right now the bullet simply drops. This is for enemies and I want to have a grenade type effect. I instantiate the bullet like so in the gun script:
Instantiate(bullet, bulletSpawn.transform.position, transform.rotation);
the bullet should be set to the gun's rotation, is this correct?
In the bullet movement script I thought I would be able to simply use transform.forward because the bullet rotation would be the same as the guns rotation when the bullet was instantiated.
void FixedUpdate () { Vector3 rot = transform.forard; rigidbody2D.AddForce(rot * speed);
}//late update
Any help would be greatly appreciated. Thanks.
Answer by MakeCodeNow · Feb 17, 2014 at 02:42 AM
This code looks reasonable, but just set the velocity. That's plenty correct in this case.
I tried using rigidbody2D.velocity, it didn't make a difference. I've read that using transform.forward for 2D doesn't work, so I tried using transform.right. Now the ball flies to the right of the screen regardless of the enemy facing to the right or left.