Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var runSpeedScale = 1.0;
- var walkSpeedScale = 1.0;
- function Start ()
- {
- // By default loop all animations
- GetComponent.<Animation>().wrapMode = WrapMode.Loop;
- GetComponent.animation["run"].layer = -1;
- GetComponent.animation["walk"].layer = 1;
- GetComponent.Animation["idle"].layer = 0;
- GetComponent.animation.SyncLayer(-1);
- GetComponent.animation["ledgefall"].layer = 9;
- GetComponent.animation["ledgefall"].wrapMode = WrapMode.Loop;
- // The jump animation is clamped and overrides all others
- GetComponent.animation["jump"].layer = 10;
- GetComponent.animation["jump"].wrapMode = WrapMode.ClampForever;
- GetComponent.animation["jumpfall"].layer = 10;
- GetComponent.animation["jumpfall"].wrapMode = WrapMode.ClampForever;
- // This is the jet-pack controlled descent animation.
- GetComponent.animation["jetpackjump"].layer = 10;
- GetComponent.animation["jetpackjump"].wrapMode = WrapMode.ClampForever;
- GetComponent.animation["jumpland"].layer = 10;
- GetComponent.animation["jumpland"].wrapMode = WrapMode.Once;
- GetComponent.animation["walljump"].layer = 11;
- GetComponent.animation["walljump"].wrapMode = WrapMode.Once;
- // we actually use this as a "got hit" animation
- GetComponent.animation["buttstomp"].speed = 0.15;
- GetComponent.animation["buttstomp"].layer = 20;
- GetComponent.animation["buttstomp"].wrapMode = WrapMode.Once;
- var punch = GetComponent.animation("punch");
- punch.wrapMode = WrapMode.Once;
- // We are in full control here - don't let any other animations play when we start
- GetComponent.animation.Stop();
- GetComponent.animation.Play("idle");
- }
- function Update ()
- {
- var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
- var currentSpeed = playerController.GetSpeed();
- // Fade in run
- if (currentSpeed > playerController.walkSpeed)
- {
- GetComponent.animation.CrossFade("run");
- // We fade out jumpland quick otherwise we get sliding feet
- GetComponent.animation.Blend("jumpland", 0);
- }
- // Fade in walk
- else if (currentSpeed > 0.1)
- {
- GetComponent.animation.CrossFade("walk");
- // We fade out jumpland realy quick otherwise we get sliding feet
- GetComponent.animation.Blend("jumpland", 0);
- }
- // Fade out walk and run
- else
- {
- GetComponent.animation.Blend("walk", 0.0, 0.3);
- GetComponent.animation.Blend("run", 0.0, 0.3);
- GetComponent.animation.Blend("run", 0.0, 0.3);
- }
- GetComponent.animation("run").normalizedSpeed = runSpeedScale;
- GetComponent.animation("walk").normalizedSpeed = walkSpeedScale;
- if (playerController.IsJumping ())
- {
- if (playerController.IsControlledDescent())
- {
- GetComponent.animation.CrossFade ("jetpackjump", 0.2);
- }
- else if (playerController.HasJumpReachedApex ())
- {
- GetComponent.animation.CrossFade ("jumpfall", 0.2);
- }
- else
- {
- GetComponent.animation.CrossFade ("jump", 0.2);
- }
- }
- // We fell down somewhere
- else if (!playerController.IsGroundedWithTimeout())
- {
- GetComponent.animation.CrossFade ("ledgefall", 0.2);
- }
- // We are not falling down anymore
- else
- {
- GetComponent.animation.Blend ("ledgefall", 0.0, 0.2);
- }
- }
- function DidLand () {
- GetComponent.animation.Play("jumpland");
- }
- function DidButtStomp () {
- GetComponent.animation.CrossFade("buttstomp", 0.1);
- GetComponent.animation.CrossFadeQueued("jumpland", 0.2);
- }
- function Slam () {
- GetComponent.animation.CrossFade("buttstomp", 0.2);
- var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
- while(!playerController.IsGrounded())
- {
- yield;
- }
- GetComponent.animation.Blend("buttstomp", 0, 0);
- }
- function DidWallJump ()
- {
- // Wall jump animation is played without fade.
- // We are turning the character controller 180 degrees around when doing a wall jump so the animation accounts for that.
- // But we really have to make sure that the animation is in full control so
- // that we don't do weird blends between 180 degree apart rotations
- GetComponent.animation.Play ("walljump");
- }
- @script AddComponentMenu ("Third Person Player/Third Person Player Animation")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement