- Home /
Animation velocity and magnitude
Okay, so I have been creating a fps shooter game, I am still very inexperienced with java and so have been following tutorials on youtube. One part of the tutorial is animation speed so it builds up and gets faster as you move and if you run into a object it stop. I have the code as it should be (I think) but the animations don't play properly they go to the first frame and do not continue. I will paste the code for my game below the lines that are commented out are the one causing me problems any help is appreciated.
var PlayerState : float;
var PlayerAnimSec : GameObject;
//var JumpingAnimation : GameObject;
var PlayerMotor : CharacterMotor;
var WalkingSpeed : float = 6;
var AimingInSpeed : float = 2;
var SprintingSpeed : float = 10;
//var PlayerBossController : CharacterController;
//var CharacterMag : float;
//var Jumped : boolean;
function Update ()
{
PlayerStateController();
PlayerAnims ();
//CharacterMag = PlayerBossController.velocity.magnitude;
}
function PlayerStateController()
{
if ((Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0))
{
if (Input.GetButton("Sprint")&&!Input.GetMouseButton(1))
{
PlayerState = 2;
}
else if (Input.GetMouseButton(1) && ! Input.GetButton ("Sprint"))
{
PlayerState = 3;
}
else
{
PlayerState = 1;
}
}
else
if (!Input.GetMouseButton(1))
{
PlayerState = 0;
}
else if (Input.GetMouseButton(1) && ! Input.GetButton ("Sprint"))
{
PlayerState = 3;
}
}
function PlayerAnims ()
{
//if (Jumped && !PlayerBossController.isGrounded)
//{
//Jumped = false;
//JumpingAnimation.animation.Play("JumpUp");
//}
//if (!Jumped && PlayerBossController.isGrounded)
//{
//Jumped = true;
//JumpingAnimation.animation.Play("JumpLand");
//}
if (PlayerState == 0)
{
PlayerAnimSec.animation.CrossFade("IdleV3");
}
else if (PlayerState == 1)
{
//PlayerAnimSec.animation["Walk"].speed = CharacterMag/WalkingSpeed;
PlayerAnimSec.animation.CrossFade("Walk");
PlayerMotor.movement.maxForwardSpeed = WalkingSpeed;
PlayerMotor.movement.maxBackwardsSpeed = WalkingSpeed/2;
PlayerMotor.movement.maxSidewardsSpeed = WalkingSpeed;
}
else if (PlayerState == 2)
{
//PlayerAnimSec.animation["Sprint"].speed = CharacterMag/SprintingSpeed;
PlayerAnimSec.animation.CrossFade("Sprint");
PlayerMotor.movement.maxForwardSpeed = SprintingSpeed;
PlayerMotor.movement.maxBackwardsSpeed = SprintingSpeed/2;
PlayerMotor.movement.maxSidewardsSpeed = SprintingSpeed;
}
else if (PlayerState == 3)
{
PlayerAnimSec.animation.CrossFade("AimingIn");
PlayerMotor.movement.maxForwardSpeed = AimingInSpeed;
PlayerMotor.movement.maxBackwardsSpeed = AimingInSpeed/2;
PlayerMotor.movement.maxSidewardsSpeed = AimingInSpeed;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613101153im_/https://answers.unity.com/themes/thub/images/avi.jpg)