LookAt(); is rotating object to the wrong side

Hi there.
This is the third time I’m writing this post as first time DNS server crashed when I posted it, resulting in loss of all text, second time I’ve lost electricity… Let’s hope this one goes through!

I’m posting here as last straw to find solution.
This means that I have googled and tried many different solutions that work for others. None works for me.

I have problem with LookAt rotations.
I’m using sample AI wander script that I’ve found here :

 #pragma strict
    var Speed= 10;
    var wayPoint : Vector3;
    function Start(){
       //initialise the target way point
    function Update() 
       transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;
        if((transform.position - wayPoint).magnitude < 3)
            // when the distance between us and the target is less than 3
            // create a new way point target
    function Wander()
       // does nothing except pick a new destination to go to
        wayPoint= Random.insideUnitSphere *5;
        wayPoint.y = 0.5;
       // don't need to change direction every frame seeing as you walk in a straight line only
        Debug.Log(wayPoint + " and " + (transform.position - wayPoint).magnitude);

Now, I have an AI model of stick figure that stands on the ground. Once script runs it rotates that gameObject wrong so it looks like character is lying in the air…

Simple solution would be to parent this gameObject, but that’s not exactly what I’m looking for because I will have many different AI characters wandering around, each one of them having same/similar/modified script attached.

I googled for hours and tried many solutions but none really helped :

I tried to adjust all codes found on those links but I couldn’t make it work. (Tried Quaternion as well) No matter what I did I would end up with that weird rotation.

I’m also having this problem in my “Click to move” script, that I picked up from web and modified. But I handled that with parent, tho for sure I would like to fix it properly.
But nevermind that, If we manage to find solution for this issue I might find other one myself :slight_smile: Used this script just for an example.

Thanks !

You said you “fixed the rotation”, but you didn’t:

wrong rotation

As you can see the blue arrow, which is your forward direction points upwards. When you do a LookAt, Unity will point the blue arrow towards your target and the green arrow upwards.

You have to create a new empty gameobject, attach your AI script there and make your model a child of the new gameobject. This new gameobject will be your actual object which moves around with the blue axis pointing forward and the green one upwards.

Here you can see the new Gameobject i created. I called it Walker. Here you have to attach your AI script. This will be the object which moves around:
New Parent Object

Here you see your model as child object. This object don’t have the AI script attached. It’s just the model of the walker. Note how the child object is rotated inside the parent. Now the parent’s forward axis (the blue one) points actually forward. I also put the new parent at the bottom as it will simplify movement. You just need to move your child object upwards so the feet hit the ground:

Model As Child