- Home /
Prefab Shooting
Hi! I made an FPS Game with Prefab shooting, but I got this issue where the bullet bounces the player into the sky. I know why this happens, It's because it has a Collider. My issue though is I need that collider. If it's important, here's my Shooting and Bullet Damage Code Shooting: using System.Collections; using UnityEngine;
public class Gun : MonoBehaviour
{
public Rigidbody projectile;
public float speed = 20;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("fire1"))
{
Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
}
}
Bullet Damage:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletDamage : MonoBehaviour
{
public int damageAmount = 10;
public void OnCollisionEnter(Collision col)
{
if(col.rigidbody)
{
col.rigidbody.GetComponent<PlayerHealth>().TakeDamage(damageAmount);
}
}
}
Any help is greatly appreciated.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613000346im_/https://answers.unity.com/themes/thub/images/avi.jpg)