- Home /
How do I limit AI controlled object turns on L and T shape crossroads?
Hey, guys!
I'm new to C# and Unity. Trying to make a simple chasing game in my free time.
The goal is to catch an object under AI controls with an object controlled by a player. AI and the player can move only by road.
Level example - https://prnt.sc/u41ti3
I move both objects with transform.forward speed* and turn them with 90 and -90 angles with Turn Triggers. Screenshot - https://prnt.sc/u41wzb
I have several questions: 1. How to limit AI turns on L and T shape crossroads? I have no problems with 4 side crossroads type. 2. I need to know from which side AI approaches to the crossroad to make the correct turn.
AI object turning script code:
using System.Collections; using System.Collections.Generic; using System.Numerics; using UnityEngine;
public class TargetObjectRotator : MonoBehaviour { private readonly int[] directions = { 0, 90, -90 };
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("TurnTriggerFree"))
{
transform.Rotate(0, directions[Random.Range(0, 3)], 0, Space.Self);
}
}
}
Trying to solve the issues for about 3 days already. Or maybe there are any other more elegant solutions. Would appreciate any help. Thanks!
Your answer
Follow this Question
Related Questions
How to do AI pathfinding on trees and other vertical surfaces? 0 Answers
Automatic nav mesh generation 2 Answers
Manual OffMeshLink Max Distance? 1 Answer
Get NavMeshAgent to look where it's going 0 Answers
Problem with "Bake" (Navigation) 1 Answer