i have simple random raycasting movement script for the enemy no the enemy isnt suppose to attack me just wonder . The problem is that the enemy just spins in place my enemy for now has been a capsule because i still testing everything and stuff i am using a charcter controller and no rigidbody it just messed it all trust me this a very basic script so if can help I’ll be happy I still new to C# if anyone has a better script or soloution please help .
(mind bad spelling this code got me tired)
,So i have a simple random movement scripts here but it seems to have failed me the scripts allows the "enemy " to move around randomly but instead it just spins in circle and i can’t do anything to fix adding a rigidbody makes it worse and yes i am using a character controller and nothing i have with and character controller please help if you can here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WanderingAI : MonoBehaviour
{
public float speed = 3.0f;
public float obstacleRange = 5.0f;
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(0, 0, speed * Time.deltaTime);
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if(Physics.SphereCast(ray, 0.75f, out hit))
{
if (hit.distance < obstacleRange);
{
float angle = Random.Range(-180, 180);
transform.Rotate(0, angle, 0);
}
}
}
}