Detect Direction of Collision | AI Lane Switching


I’m currently developing a 2D Horse Racing game which has a lane system which consists of;

  • Inner Lane (The most optimal)
  • Middle Lane (2 wide (usually just for overtakes)
  • Outer Lane (3 wide mostly used in final drive)

What is currently happening is the horses are detecting the collisions, the code then sets the waypoint system to the middle lane (for the overtake) however due to this being on the HorseHandler script all horses are moving into the middle lane hence no actual overtake happening.

What i need to find out is how to detect a direction of collision, as my theory is if collided from the front then move into overtake lane.

My second question is what is the logic for moving back into the optimal/inner lane or from outer to middle? The horses don’t want to be colliding from side to side, so how would i know if the space on the inner side of the horse is free, also this will help with the overtakes if the overtake space isn’t free?

Thanks for any advice or help :slight_smile: