Hello, My enemies are floating above the ground? How can I get them to walk like attached tog round? Code (csharp): using UnityEngine; using System.Collections; public class AdvancedAI : MonoBehaviour { float distance; public float lookAtDistance = 25.0F; public float chaseRange = 2050.0F; public float attackRange =4.5F ; public float moveSpeed = 5.0F; public float damping = 6.0F; public float damage = 30.0F; public float attackRepeatTime = .8F; public Transform target; public CharacterController controller; private float verticalMomentum = 0f; private float gravity = -9.8f; private Vector3 moveDirection = Vector3.zero; private float attackTime; //TODO: add in a function to find controller and to locate and assign the player as the target void Start() { attackTime = Time.time; } void Update() { distance = Vector3.Distance(target.position, transform.position); verticalMomentum += gravity * Time.deltaTime; if(distance < lookAtDistance) { LookAt(); } if (distance < attackRange) { AttackPlayer(); } else if (distance < chaseRange) { ChasePlayer(); } } void LookAt() { Quaternion rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } void ChasePlayer() { moveDirection = transform.forward; moveDirection *= moveSpeed; moveDirection.y += verticalMomentum * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); } void AttackPlayer() { //TODO: Need Attack Animations if (Time.time > attackTime) { target.SendMessage("damagePlayer", damage, SendMessageOptions.DontRequireReceiver); attackTime = Time.time + attackRepeatTime; } } void ApplyDamage() { chaseRange += 15; moveSpeed += 1; lookAtDistance += 20; } }
Sorry, this is not my field of expertise, but you are changing verticalMomentum twice (once in Update and again when calling your function) and also should you not be checking if the controller is grounded when doing those calculations?
you're also multiplying by time.deltaTime twice, lines 36 and 65, so it's going to be tiny once applied