- Home /
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!
Answer by hijinxbassist · Mar 17, 2012 at 07:32 PM
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.
Answer by LegolasArc · Mar 18, 2012 at 06:22 AM
Perfect, it works , thanks a lot! Greetings
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 ins$$anonymous$$d of answers. Happy trails
Your answer
Follow this Question
Related Questions
Difference between Legacy, Humanoid and Generic model 2 Answers
Whats the script for basic Character movement? 2 Answers
Smooth Camera Follow Script, Weird Movement... Please help! 1 Answer
Character running at super speed 1 Answer
(23,34): BCE0019: 'SetButton' is not a member of 'UnityEngine.Animator'. 1 Answer