I am trying to build a 3D Turret that will shoot at the player. So far I have the turret shoot and point at the player, However when shot the bullets just keep going and the boundary I made to destroy them isn’t working. I have looked at the space Shooter tutorial on Unity’s site and it isn’t helping.
This is my boundary’s code
using UnityEngine;
using System.Collections;
public class DestroyBoundary : MonoBehaviour {
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Bullet")
{
Destroy(other.gameObject);
}
}
}
When the bullets Leave the collider they aren’t being destroyed.
This is My Bullet’s Settings
phaem
2
You should not use colliders for that. It is much easier (and cheaper) to save the timestamp or position when bullet is fired and check them against current time / current position respectively to enforce limits.
- This solution will increase (just a little) your game performance.
- It allows you to avoid speeding collision problem when bullet flying so fast it jumps through collider in 2 frames.
- Also you won’t hear about FixedUpdate/Update problem when physics cycle skipped during lag.
And one more thing. Executing game logic code in physics cycle (FixedUpdate and OnCollision/OnTrigger messages) is bad practice, avoid it where possible.