- Home /
Bullets aren't firing / Bullet holes not instantiating correctly
I've been trying to make my bullets shoot out of my gun however I've run into a couple of problems. These being when I shoot the bullet it instantiates it but the bullet just stays in 1 position and doesn't accelerate out towards the object so you end up with a load of floating bullets with colliders on (until I put destroy script on them).
The other bug I'm experiencing is when I'm firing my gun I'm expecting bullet holes to appear when the bullet collides with a object or when my Raycast for the gun hits the object. The problem I'm facing however is that the bullet holes although they're showing up on the wall they're only facing in 1 direction instead of towards the player on the object. I have got an quaternion on the bullet hole so it should turn towards the player but instead it just faces a single direction and is thus not view-able by the player.
In regards to the bulletholes I have been checking with my other scripts where I have been using quaternions for rotating of gameObjects when raycasted with absolutely no luck with it happening even when I've tried copying the code in and manipulating it for my needs on this script.
Is anybody able to help me with these bugs?
Here is the bullet script which includes the script for the bullet-holes.
BulletScript
public float maxDist;
public GameObject decalHitWall;
public float floatInFrontOfWall;
[HideInInspector]
public float lifeTime = 2.0f;
[HideInInspector]
public int bulletSpeed = 5;
// Use this for initialization
void Start ()
{
maxDist = 1000000000.0f;
floatInFrontOfWall = 0.00001f;
}
// Update is called once per frame
void Update ()
{
//transform.Translate(Vector3.down * Time.deltaTime * bulletSpeed);
//rigidbody.AddForce(transform.forward * 3000);
RaycastHit hit;
Quaternion rayObjectRotation;
if (Physics.Raycast(transform.position, transform.forward, out hit, maxDist))
{
if (decalHitWall && hit.transform.tag == "Level Parts")
{
Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall),
Quaternion.LookRotation(hit.normal));
}
Destroy(gameObject);
}
}
Here is the script I have set up for spawning of the bullet. RayShoot Code
if (keyTimer == 0)
{
if (Input.GetMouseButton (0) && bulletsLeft > 0)
{
if (shootTimer == 0)
{
PlayShootAudio();
RayFire();
Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
shootTimer = shootCooler;
keyTimer = keyCooler;
}
//transform.Translate(Vector3.down Time.deltaTime bulletSpeed); //rigidbody.AddForce(transform.forward * 3000);
Well, your bullet isn't going to move with those lines both commented out.
Your answer
Follow this Question
Related Questions
WaitForSecond Corountine Sleep Time Varies 2 Answers
Need help with my gun script! 1 Answer
Which is better, shooting a bullet from camera or from the gun itself? 3 Answers
Setting bullet instansiate direction? help? 1 Answer
Objects instantiate at prefab location instead of playtime location 1 Answer