Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var speed : float = 6.0;
- var jumpSpeed : float = 6.0;
- var gravity : float = 12.0;
- //This variable is now inheriting the Vector3 info (X,Y,Z) and setting them to 0.
- private var moveDirection : Vector3 = Vector3.zero;
- function MoveAndJump() {
- var controller : CharacterController = GetComponent(CharacterController);
- if(controller.isGrounded) {
- //moveDirection is inheriting Vector3 info. This now sets the X and Z coords to receive the input set to "Horizontal" and "Vertical"
- moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows player Input
- moveDirection = transform.TransformDirection(moveDirection); //How to move
- moveDirection *= speed; //How fast to move
- if(Input.GetButtonDown("Jump")) {
- animation.Play("Jump");
- moveDirection.y = jumpSpeed;
- }
- }
- //Apply gravity
- moveDirection.y -= gravity * Time.deltaTime;
- //This moves the controller
- controller.Move(moveDirection * Time.deltaTime);
- if(Input.GetButton("Fire1")){
- animation.Play("Attack");
- }
- if(Input.GetButton("Vertical")){
- animation.Play("Run");
- }
- }
- function Update() {
- MoveAndJump();
- }
- var speed : float;
- var jumpSpeed : float;
- var gravity : float;
- private var moveDirection : Vector3 = Vector3.zero;
- function MoveJumpAttack() {
- var controller : CharacterController = GetComponent(CharacterController);
- if (controller.isGrounded) {
- moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, 0);
- moveDirection *= speed;
- if (moveDirection.sqrMagnitude > 0.01)
- transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 90);
- }
- moveDirection.y -= gravity * Time.deltaTime;
- controller.Move(moveDirection * Time.deltaTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement