i made an animal and got an animal script. But if my Animal turns around it falls down. I tried to make it kinamatic but he dont had any gravity anymore
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Animal : MonoBehaviour
{
public float movementspeed = 3f;
public float rotspeed = 100f;
private bool iswandering = false;
private bool isrotleft = false;
private bool isrotright = false;
private bool iswalking = false;
private void Update()
{
if (iswandering == false)
{
StartCoroutine(Wander());
}
if (isrotright == true)
{
transform.Rotate(transform.up * Time.deltaTime * rotspeed);
}
if (isrotleft == true)
{
transform.Rotate(transform.up * Time.deltaTime * -rotspeed);
}
if (iswalking == true)
{
transform.position += transform.forward * movementspeed * Time.deltaTime;
}
}
IEnumerator Wander()
{
int rottime = Random.Range(1, 3);
int rotwait = 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(rotwait);
if (rotatelorR == 1)
{
isrotright = true;
yield return new WaitForSeconds(rottime);
isrotright = false;
}
if (rotatelorR == 2)
{
isrotleft = true;
yield return new WaitForSeconds(rottime);
isrotleft = false;
}
iswandering = false;
}
}