- Home /
Gun is shooting based on movement not camera rotation?
So I am instantiating bullets out of an emitter I have in front of my gun, but instead of to changing direction with the gun it seems to be going in a direction based on how my character is moving. (if that makes sense) So if I move to the right the bullet will travel more to the right, and if i move to the left the bullet will travel in a direction more to the left, but looking around does not affect the direction? Any help is very much appreciated!
This is my script for the instantiate: GameObject instBullet = Instantiate(bullet, emitter.transform.position, Quaternion.LookRotation(Camera.main.transform.position, Vector3.forward)) as GameObject;
Answer by Rolo552 · Feb 05, 2020 at 05:36 PM
I think the problem might in the emitter. Is the emiter part of the object that is attached to the camera ? if not make sure that the emiter is set as a child of the object.
Instead what could you do is to not copy the rotation of the camera, but the rotation of the emiter. like so.
Gameobject newProjectile = Instantiate (projectilePrefab, muzzle.position, muzzle.rotation) as GameObject;