Unity Shooting Problems(Bullet)

Problem:My bullet just bounces off the wall every time I shoot and hit a wall,any fix?
My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletController : MonoBehaviour
{
public float moveSpeed, lifeTime;
public Rigidbody theRB;
// Start is called before the first frame update
void Update()
{
theRB.velocity = transform.forward * moveSpeed;
lifeTime -= Time.deltaTime;
if (lifeTime <= 0)
{
Destroy(gameObject);
}
}
private void OnTriggerEnter(Collider other)
{
Destroy(gameObject);

}
}

Did you set the collider to Trigger? Is not, then you’ll want probably OnCollisionEnter instead of OnTriggerEnter. Note that OnCollisionEnter takes a Collision argument, and not a Collider argument.

Sorry still does not work :frowning: still bouncing

You’ll need to start showing some more information. Show a screenshot of the bullet’s collider (the inspector values for it), and the trigger area’s collider. Also, show the code you’re using to propel the bullet forward.

1 Like