I have a problem with my car racing game especially in collider for NPC.
I have 4 colliders to trigger some action in my NPC but I’m still don’t know how to check which collider that collision with some object.
The two collider in front of car are use to make decision in my NPC that want to avoid the obstacle in front of the car.
If the right one hit the obstacle, the car will turn left to avoid the obstacle and vice versa.
But if both of them hit the obstacle, the NPC will activate the two collider beside the car and check the obstacle again for making decision that the NPC will turn left or right.
This is a picture about my NPC which have 4 colliders.
Attach this script to car
public class Car()
void OnTriggerEnter(Collider other)
Check out the collision functions for the Monobehaviour class, you’ll need to write some scripts to get what you want to work.
Instead of having four colliders on one game object, try attaching a collider to four separate child objects.
Then write a script with an OnTriggerEnter() function that calls a method in your main script and passes the name of the child object. (You’ll need to reference the main object’s script in your child objects).
//in script on child object
public MainScript mainScript //whatever your script is called - attach in inspector
//in main script
public void CarImpact(string trigger)