- Home /
Need help addind a attack and jump script
I have this script for my character, i need to add code somewhere to make my char jump(with the char controller) and attack(atleast play the animation once or attack with a collider)
//character controller script
public var walkSpeed : float = 1.0; public var gravity = 100.0; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController;
function Start() { charController = GetComponent(CharacterController); animation.wrapMode = WrapMode.Loop; }
function Update () { if(charController.isGrounded == true) { if(Input.GetAxis("Vertical") > .1) { if(Input.GetButton("Fire1")) { animation.CrossFade("run"); walkSpeed = 20; } else { animation["walk"].speed = 1; animation.CrossFade("walk"); walkSpeed = 5; } } else if(Input.GetAxis("Vertical") < -.1) { animation["walk"].speed = -1; animation.CrossFade("walk"); walkSpeed = 5; } else { animation.CrossFade("idle"); }
// 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");
// Calculate the movement direction (forward motion)
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity Time.deltaTime; charController.Move(moveDirection (Time.deltaTime * walkSpeed));
}