je vous link le code et un screen
merci
http://image.noelshack.com/fichiers/201 ... 8-test.png
Code : Tout sélectionner
//public
var speed:float;
var speedRotate:float;
var speedRun:float;
var gravity:float;
//privé
private var controller:CharacterController;
private var moveDirection:Vector3;
private var deltaTime:float;
private var characterContent;
function Start () {
controller = GetComponent("CharacterController");
characterContent = transform.Find("Perso");
}
function Update () {
deltaTime = Time.deltaTime;
//déplacement
if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)){
moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speedRun);
}else{
moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speed);
}
//animation
if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)){
characterContent.animation.CrossFade("idle", 0.2);
}
if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)){
characterContent.animation.CrossFade("idle", 0.2);
}
//animation fin
moveDirection = transform.TransformDirection(moveDirection);
transform.Rotate(Vector3(0,Input.GetAxis("Horizontal") * deltaTime * speedRotate,0));
//gravité
moveDirection.y -= gravity;
controller.Move(moveDirection * deltaTime);
}