- Home /
Question by
saurabhn04 · Jul 29, 2013 at 04:15 PM ·
movementscharacter.move
character does not move horizontally
the code that i have used is:
#pragma strict
var walkSpeed : float = 7;
var gravity : float = 50;
var rotationSpeed : float = 7;
var body : Transform;
public var yRot : float;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var height : Vector3 = transform.TransformDirection(Vector3.up);
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
animation.CrossFade("run", 0.2);
animation["run"].speed = walkSpeed/10;
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical")))* Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal")))* Time.deltaTime);
}else{
animation.CrossFade("idle", 0.2);
}
if(Input.GetAxis("Mouse X")){
yRot += 10*Input.GetAxis("Mouse X");
}
transform.rotation = Quaternion.Euler(0, yRot, 0);
Controller.Move(height * -gravity * Time.deltaTime);
}
function LateUpdate(){
// Rotate the Character to match the direction he/she is going
if(Input.GetAxis("Vertical") == 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 180;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 0;
}
}else if(Input.GetAxis("Vertical") > 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 135;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 45;
}
}else if(Input.GetAxis("Vertical") < 0){
if(Input.GetAxis("Horizontal") == 0){
body.localEulerAngles.y = -90;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -135;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -45;
}
}
}
there are no errors but the character does not move horizontally. can some one tell me what the problem is? Please :)
Comment
I stripped animations (because i have none) and tested it and it works.