Help me with my ai controller
Hello, i'm working on a game and i get this weird behaviour :
here is my code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OuvrierController : MonoBehaviour
{
private GameObject marmottes;
private bool wandering = true;
void Start()
{
marmottes = GameObject.Find("Marmottes");
}
// Update is called once per frame
void Update()
{
if(wandering) {
WanderAround();
}
}
void WanderAround() {
Collider[] hitColliders = Physics.OverlapSphere(transform.position, 1);
List<GameObject> outcomes = new List<GameObject>();
foreach (var hitCollider in hitColliders)
{
if(hitCollider.gameObject.name == "groundTile") {
outcomes.Add(hitCollider.gameObject);
}
}
int targetID = (int)(Random.value*outcomes.Count);
Vector3 target = outcomes[targetID].transform.position;
transform.position = target;
outcomes.Clear();
}
}
When doing this the character moves randomly at insane speed but it's normal. The problem is that the character is IN the groundTile, so i tried to set the y to 1.5 (the height i needed) with a huge lot of different ways, but everytime the character stops to move. Do anyone have an idea why ?
The problem here is that you are moving this guy to a random tile every frame
I know, but this is what i want the problem is when i give it a different y position than the tile, then he stops moving
Answer by Mouton_redstone · Mar 27 at 04:16 PM
EDIT : The circle was too small to detect adjacent tiles, entering it into the ground helps the detection range to detect the other tiles
Your answer
Follow this Question
Related Questions
Set Transform.up and rotate at the same time 1 Answer
Question about Vector creation 1 Answer
Applying direction into transform position 0 Answers
Player Floating 0 Answers