Hello everyone,
I am creating a racing game. There are total 4 cars (1 player and 3 cpu) and what I want is all cars mustn’t collide with each other (They all behave like ghost to each other). I read documentation in unity on IgnoreCollision (Unity - Scripting API: Physics.IgnoreCollision) but as I am completely new in coding I don’t understand it clearly. Please help me on writing script for this.
Attach this script to each car
using UnityEngine;
[RequireComponent(typeof(Collider))]
public class IgnoreCollisionWith : MonoBehaviour
{
// Fill the inspector with the collider of the **other cars**
[SerializeField] private Collider[] otherColliders;
private void Start()
{
Collider collider = GetComponent<Collider>();
foreach(Collider otherCollider in otherColliders)
Physics.IgnoreCollision(collider, otherCollider);
}
}