- Home /
Animation problem with rotation and position.
Hi I'm making a simple FPS game, and I made some animations (Idle, walking and running). I script then all so when I'm not moving the idle animation plays, when I start walking the walking animation plays and when I press shift the running animation plays. However, once I let go the shift button (running animation button) the rotation of my game object (hands and gun) doesn't change and the position does. So, it play the walking and idle animation with the rotation of the running animation. Any help? Thanks
The script I'm using is
using UnityEngine; using System.Collections;
public class PlayerControler : MonoBehaviour { public CharacterController CharCont; public CharacterMotor CharMotor;
//Holders for weapons
public Transform WalkAnimationHolder;
public Transform JumpAnimationHolder;
public Transform SwayHolder;
public Transform RecoilHolder;
public WalkingState walkingstate = WalkingState.Idle;
public float VelocityMagnitude;
public void FixedUpdate()
{
AnimationController();
SwayController();
SpeedController();
VelocityMagnitude = CharCont.velocity.magnitude;
}
public void SpeedController()
{
if((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0)
{
if(Input.GetButton("Run"))
{
walkingstate = WalkingState.Running;
}
else
{
walkingstate = WalkingState.Walking;
}
}
else
{
walkingstate = WalkingState.Idle;
}
}
public void AnimationController()
{
if(walkingstate == WalkingState.Running)
{
WalkAnimationHolder.animation.Play("WeaponRun");
}
else if(walkingstate == WalkingState.Walking)
{
WalkAnimationHolder.animation.Play("WeaponWalk");
}
else
{
WalkAnimationHolder.animation.Play("WeaponIdle");
}
}
public void SwayController()
{
}
}
public enum WalkingState { Idle, Walking, Running }
Your answer
Follow this Question
Related Questions
Simple animation problem 0 Answers
Rotation in animation problem 0 Answers
Prefab Character position/rotation resets 0 Answers
Lerping smoothly between animation and new position 2 Answers
Skateboarding Rotation Problem 1 Answer