Turret use spherecast to detect enemy and fire.
The problem is after firing shell, spherecast will return shell as hit object, i need spherecast to ignore the shell.
In the editor, project setting, physics, ignore raycast and shell is unticked , but it does’t work.
I tried this and that for few hrs, but still cannot solve it.
void Fire()
{
RaycastHit hit;
if (Physics.SphereCast(barrel.position, shellRadius, direction, out hit, attackRange))
{
s=hit.transform.name;
if(nextFire < Time.time && hit.transform.gameObject.layer ==enemyLayer)
{
nextFire = Time.time + fireRate;
GameObject shell = Instantiate(Resources.Load("RailGunShell"), barrel.position, barrel.rotation) as GameObject;
shell.GetComponent<Rigidbody>().AddForce(direction * shellSpeed);
}
}