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 ?