I have set up a player controller with different empties that are assigned to parts of my script. I have one for movement which contains the walk, idle, and sprint animations. In my C# script I have a speed based animation controller, which makes the animation Idle when the playerspeed is 0, it makes the player walk when the speed is 3.5, and sprint when it is 7.5. I had it working before, but then I used a tutorial for aiming down sights (ADS). Now I can aim down the sights, but whenever I sprint the default position of the gun changes to the first frame of the sprint animation, but still has the idle, firing, jumping and walking animations, just oriented to the first sprint frame. Any ideas???
Here is part of the code:
public void SpeedController()
{
if((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0)
{
if(Input.GetButton("Run"))
{
walkingstate = WalkingState.Running;
CharMotor.movement.maxForwardSpeed = RunSpeed;
CharMotor.movement.maxSidewaysSpeed = RunSpeed;
CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2;
}
else
{
walkingstate = WalkingState.Walking;
CharMotor.movement.maxForwardSpeed = WalkSpeed;
CharMotor.movement.maxSidewaysSpeed = WalkSpeed;
CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2;
}
}
else
{
walkingstate = WalkingState.Idle;
}
}
public void AnimationController()
{
if (WasStanding && !CharCont.isGrounded)
{
WasStanding = false;
JumpAnimationHolder.animation.Play("Jump 1");
}
else if (!WasStanding && CharCont.isGrounded)
{
WasStanding = true;
JumpAnimationHolder.animation.Play("Land 1");
}
if (walkingstate == WalkingState.Running)
{
WalkAnimationHolder.animation["Sprint 1"].speed = VelocityMagnitude / RunSpeed;
WalkAnimationHolder.animation.CrossFade("Sprint 1", 0.2f);
}
else if (walkingstate == WalkingState.Walking)
{
WalkAnimationHolder.animation["Walk 1"].speed = VelocityMagnitude / WalkSpeed;
WalkAnimationHolder.animation.CrossFade("Walk 1",0.2f);
}
else
{
WalkAnimationHolder.animation.CrossFade("Idle 1",0.2f);
}
}
public void ADSController()
{
if (Input.GetButton("Fire2"))
{
IsAiming = true;
ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].adsposition, 0.25f);
PlayerCamera.camera.fieldOfView = Mathf.Lerp(PlayerCamera.camera.fieldOfView, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].fov, 0.25f);
}
else
{
IsAiming = false;
ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, Vector3.zero, 0.25f);
PlayerCamera.camera.fieldOfView = Mathf.Lerp(PlayerCamera.camera.fieldOfView, 60, 0.25f);
}
}
}