x


Help! Models chasing me with their backside!

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!

more ▼

asked Sep 04 '11 at 02:34 PM

NellacKun gravatar image

NellacKun
1 3 3 5

LOL, LMAO.

Sep 05 '11 at 01:39 PM Dryden Richardson

It is pretty hilarious looking. But I really need to find out why it's doing it. :)

Sep 05 '11 at 03:26 PM NellacKun
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

I believe that one of two things happened.

  • 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.
more ▼

answered Sep 04 '11 at 03:12 PM

Peter G gravatar image

Peter G
15k 16 44 136

To fix the model in Max, select all the verts (not the entire model -- make sure you are in vert select mode and select all of them.) Then rotate them 180 on Y so it faces +Z (Z is the blue arrow in Max, and in Unity.) In Blender you can start a Y-spin and then type "180," to get it exact.

Rotating the model, or using the export settings will change the Transform, which your script will overwrite.

Sep 04 '11 at 07:37 PM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left

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);
    }
}
more ▼

answered Sep 04 '11 at 02:51 PM

aldonaletto gravatar image

aldonaletto
41.4k 16 42 197

(comments are locked)
10|3000 characters needed characters left

Here's the code I use, it's very simple.

Maybe it's something todo with how I'm exporting it from 3DS Max?

var Player : Transform;

private var MoveSpeed : float = 0.3;
private var RotationSpeed : float = 0.5;




function Update () 
{

        //Moving the character
        transform.position += transform.forward * MoveSpeed * Time.deltaTime;

        //Face the player
        MyDestination = Player.position;
        transform.rotation = Quaternion.Slerp(transform.rotation , Quaternion.LookRotation(MyDestination - transform.position), RotationSpeed * Time.deltaTime);
}
more ▼

answered Sep 04 '11 at 05:23 PM

NellacKun gravatar image

NellacKun
1 3 3 5

You are moving in the enemy forward direction, but at the same time you're turning to the player, what can produce crazy results. Find the player direction, then walk in this direction while rotating to face the player. I included here a chaseDistance - the enemy will do nothing while the player is too far. You can remove this, or set chaseDistance to 10000 to make the enemy always chase the player.

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.forward = Vector3.Lerp(transform.forward, playerDir, RotationSpeed * Time.deltaTime);
    }
}

NOTE: I fixed an error in the last line (transform.forward was written transform.rotation...)

Sep 04 '11 at 07:45 PM aldonaletto
(comments are locked)
10|3000 characters needed characters left

Thanks guys,

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

more ▼

answered Sep 04 '11 at 06:14 PM

NellacKun gravatar image

NellacKun
1 3 3 5

Hey all,

I tried your script Aldonaletto, but it doesn't work. Gives this as a error: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.Quaternion'.

I tried rotating the vertices, but that didn't seem to work for me. ( maybe I did it wrong :x )

I loaded up a model from a pack I bought and exported it. And the script works perfectly with it, it chases face first. Which leads me to believe that something is wrong with my model?

I'm still learning 3DS Max, and Unity. So I know I'm screwing something up somewhere.

I thank you all for your help, it's greatly appreciated!

Sep 05 '11 at 01:02 PM NellacKun

My fault! I used transform.forward instead of transform.rotation, but forgot to alter the left side of the last statement! I fixed it in the code, at the other comment. Give it a try if you have problems with your algorithm.

Sep 05 '11 at 03:55 PM aldonaletto

Thanks for the update, works great now. But unfortunately, my model still goes toward my player backside first. :(

Sep 05 '11 at 04:18 PM NellacKun

Well, I think the only way is to child your model to the enemy object, and adjust it's rotation at the Inspector to (0, 180,0)

Sep 05 '11 at 04:59 PM aldonaletto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x316
x155
x25

asked: Sep 04 '11 at 02:34 PM

Seen: 669 times

Last Updated: Sep 05 '11 at 04:59 PM