Question by
unity_GZLbBX8PdI5Kkw · Apr 13, 2020 at 09:49 AM ·
rotationrigidbodyrigidbody.addforce
Problems with firing a bullet
I want my character to fire a bullet, but I have two problems: First, the bullet doesn't rotate right, so it always has the same rotation, no matter where the gun faces, second, my bullet doesn't move for some reason.
public GameObject Boolet;
public Transform Muzzle;
public GameObject Shotbullet;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
Shotbullet = Instantiate(Boolet, Muzzle.transform.position, Muzzle.transform.rotation);
Shotbullet.GetComponent<Rigidbody>().AddForce(transform.forward * Bulletspeed, ForceMode.Impulse);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make a cube rotate while moving? 1 Answer
How to freeze all constraints on rigidbody except transform.forward? 0 Answers
i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers
Rotate GameObject based on RigidBody Velocity 1 Answer
Rotations on "picked up" object 0 Answers