@McMayhem Hello, Does anyone know why my enemy is chasing me sideways instead of forward he is literally running after me with his eyes to the left? Here's his AI Thanks! 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 gravity =20.0F; public float damage = 40.0F; public float attackRepeatTime = .8F; public Transform target; public CharacterController controller; 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); if(distance < lookAtDistance) { LookAt(); } if(distance > lookAtDistance) { } 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 -= gravity * Time.deltaTime; // doesn't seem to work right :( 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 += 30; moveSpeed += 2; lookAtDistance += 40; } }
Is it just his eyes that are off target, or the whole body? I don't see anything that might cause that kind of problem from this script. Though it's a bit difficult to know for sure since I don't know how the AI's GameObject is set up in your scene. Is the transform of your AI character (where the bones and mesh are) facing the same direction as it's parent game object? (I'm assuming here that you've set up a GameObject hierarchy where the actual model of the character is stored in a GameObject that houses all the main AI code.
The code code works fine, like McMayhem says check your character model hierarchy and place the code in current place.
Check the axis your model is aligned to, sounds like it isn't facing the correct way. I think forward is along the z-axis
You need to look at your model in the editor, look at the axis arrows on the enemy & ensure that it is facing the z axis. It's rotation can be 0,0,0 & it faces the wrong way if it has been built or imported incorrectly.
It depends how you got the model. I've only imported a model once that came in on the wrong axis & the only way I could fix it was to go into blender (where I made the model), rotate it & then reimport it. I kept doing this until I got it into Unity on the correct rotation. Others may know of a better way to do this though.
Well i have a ton of things attatched, so im not sure what to do? Should i wait to see if anyone else has ideas and then if not pm you?
I can't help beyond that, I just prototype with primitives or 2d sprites without animations or stuff as I'm not skilled enough to be working on anything that needs finished art. It's more important for me at this stage to get my stuff to play well first before I worry about how it looks. Sorry.