Hi I have an enemy AI with wanders around the place, I added a rigid body to it so it has gravity, the thing is, it won’t collide with the walls, I’ve tried doing that with every Collider Component I could find, so I think that the solution is making the colliding system in the wandering script, but I have no idea of how to do that.
This is my wandering script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WanderingAI : MonoBehaviour
{
public float moveSpeed = 3f;
public float rotSpeed = 100f;
private bool isWandering = false;
private bool isRotatingLeft = false;
private bool isRotatingRight = false;
private bool isWalking = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(isWandering == false)
{
StartCoroutine(Wander());
}
if(isRotatingRight == true)
{
transform.Rotate(transform.up * Time.deltaTime * rotSpeed);
}
if (isRotatingLeft == true)
{
transform.Rotate(transform.up * Time.deltaTime * -rotSpeed);
}
if(isWalking == true)
{
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
}
IEnumerator Wander()
{
int rotTime = Random.Range(1, 3);
int rotateWait = Random.Range(1, 4);
int rotateLorR = Random.Range(0, 3);
int walkWait = Random.Range(1, 4);
int walkTime = Random.Range(1, 5);
isWandering = true;
yield return new WaitForSeconds(walkWait);
isWalking = true;
yield return new WaitForSeconds(walkTime);
isWalking = false;
yield return new WaitForSeconds(rotateWait);
if (rotateLorR == 1)
{
isRotatingRight = true;
yield return new WaitForSeconds(rotTime);
isRotatingRight = false;
}
if (rotateLorR == 2)
{
isRotatingLeft = true;
yield return new WaitForSeconds(rotTime);
isRotatingLeft = false;
}
isWandering = false;
}
}