I made and animated a simple model in 3DS Max and exported with Y direction being up. Everything seems to work just fine, except when I replaced my capsule placeholder with the model, he chases me ass first. ;(
I’ve tried rotating the model, but as soon as he locks on to my position, he rotates around again and chases me with his backside.
I’m a noob, so any help would be greatly appreciated!
Either you are rotating your model to the exactly opposite rotation. In that case, we need to see your rotation code to tell you how to fix it.
More likely however is that you modeled your character facing the wrong direction. You want them facing the z+ axis in your modeler. You can either rotate the character in your modeler, or do what is suggested here. Parent it to an empty GO, then have all the movement and rotation affect the GO. Your character should work fine then.
You’re probably assigning a new rotation to the enemy when it finds you, what replaces the one you’ve set at the Editor. If you’re using a CharacterController, drag the model to your enemy (child the model to it) and adjust the model orientation - the model will keep its relative rotation when the enemy turns to follow you. But if it doesn’t work, then probably the problem is in your script: post it here and we will check what’s wrong.
EDITED: This is the code modified to go directly to the player while rotating to face it (you were going in the enemy forward direction while rotating to the player, what can give crazy results). If the enemy has a rigidbody, freeze rotations.
var Player : Transform;
var chaseDistance: float = 30;
private var MoveSpeed : float = 0.3;
private var RotationSpeed : float = 0.5;
function Update ()
{
var playerDir = Player.position-transform.position;
if (playerDir.magnitude < chaseDistance){
//Moving the character to the player
transform.position += playerDir.normalized * MoveSpeed * Time.deltaTime;
//Face the player - using Vector3.Lerp is easier because we already have the dest vector
transform.rotation = Vector3.Lerp(transform.forward, playerDir, RotationSpeed * Time.deltaTime);
}
}
Parenting it to a empty game object, and applying the scripts to the GO instead of the model itself seems to fix it a little bit getting the rotation to line up correctly is a pain. I’m now having other troubles, like after awhile of chasing, the model goes crazy and starts clipping through the ground while spinning like crazy. I locked it’s rotation under it’s rigidbody, but no avail.
Does anyone know a fix for this? I dont really like these hokey pokey work arounds. I would very much like to know how to export this properly =D