- Home /
Instantiated Bullet Force not being applied
Ok, so I used the code in the Wiki to LookAtMouse, but instead of calling it at Update I simply call it when the mouse is Clicked and put a speed of 100 so it instantly rotates my barrel and bullet spawn point in the direction I want to fire. Initially this worked, but my bullet only fired straight forward instead of the direction my round is being fired. I added the following code and bullet clearly fires out of the barrel in the direction intended, but freezes.
if(Input.GetButtonDown("Fire2")) { positionRightBarrel.UpdateGunBarrelPosition(); audio.PlayOneShot(secondaryFireAudio); secondaryFireCreate = Instantiate(secondaryFirePrefab, GameObject.Find("secondaryFireSpawnPoint").transform.position, transform.rotation); secondaryFireCreate.name = "secondaryFireShot"; secondaryFireCreate.rigidbody.MoveRotation(transform.Find("secondaryFireSpawnPoint").rotation); secondaryFireCreate.rigidbody.AddForce(transform.forward * secondaryFireSpeed); } My Barrel has the LookAtMouse script and then the secondaryFireSpawnPoint is a child of this. This is well past the front of the barrel so it shouldn't be colliding with anything.
Any ideas?
EDIT:
Well, what I failed to notice was that if I steered my ship that was where the shot forward was being based on. This apparently was due to the placement of my script.
I place the script on the Barrel itself and now everything is behaving as I would like.