hi people,
i have some problems with my script for a 3rd person controller…
i made a biped in 3d max and i have a few animation to it… idle,walk,jump,and throw…
how should i script it so that my char can walk and stop the walking animation wen no key is pressed… currently i am using this scripts and it doesnt seem to work…pls help me out… what am i doing wrong…
/// This script moves the character controller forward
/// and sideways based on the arrow keys.
/// It also jumps when pressing space.
/// Make sure to attach a character controller to the same game object.
/// It is recommended that you make only one call to Move or SimpleMove per frame.
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
function Start ()
{
// We are in full control here - don’t let any other animations play when we start
// animation.Stop();
// By default loop all animations
animation.wrapMode = WrapMode.Loop;
}
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded){
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis(“Horizontal”), 0,
Input.GetAxis(“Vertical”));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetAxis(“Vertical”) > 0)
{
animation.CrossFade(“walk”);
}
if (Input.GetButton (“Jump”)) {
moveDirection.y = jumpSpeed;
animation.CrossFade(“jump”);
if(Input.GetButton (“Fire1”))
{
animation.Play(“throw”);
}
}
}
// Create an animation cycle for when the character is turning on the spot
if(Input.GetAxis(“Horizontal”) !Input.GetAxis(“Vertical”))
{
animation.CrossFade(“walk”);
}
transform.eulerAngles.y += Input.GetAxis(“Horizontal”);
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}