x


Movement doesnt work if I rotate my model

Hi!

I am having some troubles with my movement script. If I test it with a normal cylinder and a character controller mesh it works fine. The problem is, when I import my model to the scene, it changes the axis or something like that.

If I import and select all rotate values to 0 (as image): it works (of course the character is lied) http://img820.imageshack.us/img820/4668/sinrotaar.jpg

If I try to rotate the character in the position I want: http://img839.imageshack.us/img839/1065/sinrotar.jpg

It doesnt work. I think is something related to the axis, cos I only can Jump.

I add my movement script maybe I'm doing something wrong (I know my code is not the best, but I'm still starting and I have to learn a lot).

function Update () {
var controller : CharacterController = GetComponent(CharacterController);        
var right : Vector3 = transform.right * speed * Input.GetAxis("Horizontal");
var forward : Vector3 = transform.forward * speed * Input.GetAxis("Vertical");


right.y = moveDirection.y; // keep current vertical velocity
right.z = forward.z;  // z z
moveDirection = right; // but update horizontal velocity

//Doble salto
if (controller.isGrounded) {  //If the player is on the floor
    contadorsalto = 0;          //Reset the counter
    moveDirection.y = 0;
    if (Input.GetButtonDown ("Jump")) {  //When press space
       moveDirection.y = jumpSpeed;  //Jump
       contadorsalto = 1;       //Counter = 1
    }
} else {                   //If the player is NOT on the floor
    if (contadorsalto < 2) {     // and the counter is less than 2 (only 1 jump)
       if (Input.GetButtonDown ("Jump")){  //When we press space
         moveDirection.y = jumpSpeed;  //Jump
         contadorsalto = 2;          //Counter = 2 so it won't enter again until player is in the floor 
       }
    }
}

moveDirection.y -= gravity * Time.deltaTime;

controller.Move(moveDirection * Time.deltaTime);

}

Thanks in advance!

more ▼

asked Mar 17 '12 at 06:39 PM

LegolasArc gravatar image

LegolasArc
1 1 2 2

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

2 answers: sort voted first

Very common problem, i would get soo frustrated with this. All you need to do is set the pivot of your model so that Y points up, and Z points forward. In 3dsMax, you go to Affect Pivot Only and rotate it accordingly.

I didnt specify before, this will be done in the modeling program itself and not in unity. If youre not sure how to do this, do a "Search engine" search for your modeling program and how to change pivot of model.

more ▼

answered Mar 17 '12 at 07:32 PM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

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

Perfect, it works , thanks a lot! Greetings

more ▼

answered Mar 18 '12 at 06:22 AM

LegolasArc gravatar image

LegolasArc
1 1 2 2

Glad to here it! It took me a little why to understand why this was happening, but once you do you'll never forget :p Can you mark the question as answered please, the lil checkmark under the thumbs. Its also better to respond using comments instead of answers. Happy trails

Mar 18 '12 at 07:35 AM hijinxbassist
(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:

x3330
x1367
x572

asked: Mar 17 '12 at 06:39 PM

Seen: 343 times

Last Updated: Mar 18 '12 at 08:42 AM