Scene Changes and bug fixes #431

Merged
glencelow merged 9 commits from PlayerController into main 2023-03-20 17:42:41 +08:00
8 changed files with 315 additions and 41 deletions
Showing only changes of commit 9218b7b993 - Show all commits

View File

@ -3,30 +3,26 @@ using System;
public class PlayerIdleState : BaseState public class PlayerIdleState : BaseState
{ {
private bool holdItem; protected PlayerController player;
public PlayerIdleState(StateMachine stateMachine, bool hi) : base(stateMachine)
public PlayerIdleState(StateMachine stateMachine) : base(stateMachine)
{ {
stateName = "Idle State"; stateName = "Idle State";
holdItem = hi;
} }
public override void OnEnter() public override void OnEnter()
{ {
//Debug.Log("WALK ENTER");
if (PlayerAnimations.Instance) if (PlayerAnimations.Instance)
{ {
if (!holdItem) if (!machine.GetScript<PlayerController>().playLandedAnimation)
{ {
if (PlayerAnimations.Instance.playerIdleClip) if (!machine.GetScript<PlayerController>().holdItem)
{ {
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerIdleClip); PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerIdleClip); PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerIdleClip); PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerIdleClip); PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
} }
}
else else
{
if (PlayerAnimations.Instance.playerCarryIdleClip)
{ {
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip); PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip); PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
@ -34,6 +30,54 @@ public class PlayerIdleState : BaseState
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip); PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
} }
} }
else
{
PlayerAnimations.Instance.playerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpEndClip)
{
if (!machine.GetScript<PlayerController>().holdItem)
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
else
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
machine.GetScript<PlayerController>().playLandedAnimation = false;
}
});
PlayerAnimations.Instance.BagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpEndClip)
{
if (!machine.GetScript<PlayerController>().holdItem)
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
else
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
PlayerAnimations.Instance.silhoPlayerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpEndClip)
{
if (!machine.GetScript<PlayerController>().holdItem)
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
else
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
PlayerAnimations.Instance.silhoBagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpEndClip)
{
if (!machine.GetScript<PlayerController>().holdItem)
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
else
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
}
} }
} }
public override void update() public override void update()

View File

@ -10,6 +10,60 @@ public class PlayerJumpState : BaseState
public override void OnEnter() public override void OnEnter()
{ {
//Debug.Log("jump"); //Debug.Log("jump");
if (PlayerAnimations.Instance)
{
if (!machine.GetScript<PlayerController>().holdItem && PlayerAnimations.Instance.playerJumpStartClip)
{
PlayerAnimations.Instance.playerAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpStartClip);
PlayerAnimations.Instance.BagAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpStartClip);
PlayerAnimations.Instance.silhoPlayerAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpStartClip);
PlayerAnimations.Instance.silhoBagAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpStartClip);
PlayerAnimations.Instance.playerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpStartClip)
{
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
}
});
PlayerAnimations.Instance.BagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpStartClip)
{
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
}
});
PlayerAnimations.Instance.silhoPlayerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpStartClip)
{
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
}
});
PlayerAnimations.Instance.silhoBagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerJumpStartClip)
{
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
}
});
}
else if (machine.GetScript<PlayerController>().holdItem && PlayerAnimations.Instance.playerJumpLoopClip)
{
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerJumpLoopClip);
}
else
{
Debug.LogError("missing playercontroller in jump state");
}
}
} }
public override void update() public override void update()
{ {

View File

@ -9,7 +9,19 @@ public class PlayerLandState : BaseState
} }
public override void OnEnter() public override void OnEnter()
{ {
//Debug.Log("WALK ENTER"); //Debug.Log("landed ENTER");
if (PlayerAnimations.Instance)
{
if (!machine.GetScript<PlayerController>().holdItem)
{
PlayerAnimations.Instance.playerAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpEndClip);
PlayerAnimations.Instance.BagAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpEndClip);
PlayerAnimations.Instance.silhoPlayerAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpEndClip);
PlayerAnimations.Instance.silhoBagAnimator.PlayOneShot(PlayerAnimations.Instance.playerJumpEndClip);
}
else
machine.GetScript<PlayerController>().playLandedAnimation = false;
}
} }
public override void update() public override void update()
{ {

View File

@ -14,7 +14,7 @@ public class PlayerRunState : BaseState
public override void OnEnter() public override void OnEnter()
{ {
//Debug.Log("WALK ENTER"); //Debug.Log("WALK ENTER");
if (PlayerAnimations.Instance && PlayerAnimations.Instance.playerRunClip) if (PlayerAnimations.Instance)
{ {
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerRunClip); PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerRunClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerRunClip); PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerRunClip);

View File

@ -6,37 +6,37 @@ public class PlayerWalkState : BaseState
{ {
private float timer; private float timer;
private float delay = 0.5f; private float delay = 0.5f;
private bool holdItem; public PlayerWalkState(StateMachine stateMachine) : base(stateMachine)
public PlayerWalkState(StateMachine stateMachine, bool hi) : base(stateMachine)
{ {
stateName = "Walk State"; stateName = "Walk State";
holdItem = hi;
} }
public override void OnEnter() public override void OnEnter()
{ {
//Debug.Log("WALK ENTER"); //Debug.Log("WALK ENTER");
timer = delay; timer = delay;
machine.GetScript<PlayerController>().playLandedAnimation = false;
if (PlayerAnimations.Instance) if (PlayerAnimations.Instance)
{ {
if (!holdItem) if (!machine.GetScript<PlayerController>().holdItem)
{
if (PlayerAnimations.Instance.playerWalkClip)
{ {
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerWalkClip); PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerWalkClip); PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerWalkClip); PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerWalkClip); PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
} }
} else if (machine.GetScript<PlayerController>().holdItem)
else
{
if (PlayerAnimations.Instance.playerCarryWalkClip)
{ {
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip); PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip); PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip); PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip); PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
} }
else
{
Debug.LogError("Missing playercontroller in walk state");
} }
} }
} }

View File

@ -34,6 +34,13 @@ public class PickAndThrow : Script
[Tooltip("Height of ray")] [Tooltip("Height of ray")]
public float rayHeight = 0.1f; public float rayHeight = 0.1f;
[NonSerialized]
private TweenThread camArmTween;
[NonSerialized]
private TweenThread foodTween;
public float tweenDuration = 0.3f;
protected override void awake() protected override void awake()
{ {
pc = GetScript<PlayerController>(); pc = GetScript<PlayerController>();
@ -52,6 +59,10 @@ public class PickAndThrow : Script
timer = delayTimer; timer = delayTimer;
} }
protected override void start()
{
}
protected override void update() protected override void update()
{ {
if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone) if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone)
@ -96,6 +107,7 @@ public class PickAndThrow : Script
pc.holdItem = false; pc.holdItem = false;
inRange = false; inRange = false;
throwItem = true; throwItem = true;
PlayThrowAnimation();
timer = 0.0f; timer = 0.0f;
} }
@ -131,6 +143,7 @@ public class PickAndThrow : Script
{ {
pc.holdItem = true; pc.holdItem = true;
RetrieveItemComponets(); RetrieveItemComponets();
PlayPickUpAnimation();
} }
} }
} }
@ -273,5 +286,112 @@ public class PickAndThrow : Script
return (pc.camArm.Pitch - tpc.pitchUpperClamp) / (tpc.pitchLowerClamp - tpc.pitchUpperClamp); return (pc.camArm.Pitch - tpc.pitchUpperClamp) / (tpc.pitchLowerClamp - tpc.pitchUpperClamp);
} }
private void PlayPickUpAnimation()
{
if (PlayerAnimations.Instance)
{
PlayerAnimations.Instance.playerAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.playerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerPickUpClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
else
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
PlayerAnimations.Instance.BagAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.BagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerPickUpClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
else
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
PlayerAnimations.Instance.silhoPlayerAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.silhoPlayerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerPickUpClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
else
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
PlayerAnimations.Instance.silhoBagAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.silhoBagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerPickUpClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryWalkClip);
else
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerCarryIdleClip);
}
});
}
}
private void PlayThrowAnimation()
{
if (PlayerAnimations.Instance)
{
PlayerAnimations.Instance.playerAnimator.PlayOneShot(PlayerAnimations.Instance.playerThrowClip);
PlayerAnimations.Instance.playerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerThrowClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
else
PlayerAnimations.Instance.playerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
}
});
PlayerAnimations.Instance.BagAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.BagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerThrowClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
else
PlayerAnimations.Instance.BagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
}
});
PlayerAnimations.Instance.silhoPlayerAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.silhoPlayerAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerThrowClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
else
PlayerAnimations.Instance.silhoPlayerAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
}
});
PlayerAnimations.Instance.silhoBagAnimator.PlayOneShot(PlayerAnimations.Instance.playerPickUpClip);
PlayerAnimations.Instance.silhoBagAnimator.OnClipFinished.RegisterAction((x) =>
{
if (x.FinishedClip == PlayerAnimations.Instance.playerThrowClip)
{
if (pc.isMoveKeyPress)
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerWalkClip);
else
PlayerAnimations.Instance.silhoBagAnimator.Play(PlayerAnimations.Instance.playerIdleClip);
}
});
}
}
} }

View File

@ -7,17 +7,17 @@ public class PlayerAnimations : Script
{ {
#region Raccoon #region Raccoon
[SerializeField] [SerializeField]
public AnimationClipAsset playerIdleClip; // done public AnimationClipAsset playerIdleClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerWalkClip; // done public AnimationClipAsset playerWalkClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerRunClip; // done public AnimationClipAsset playerRunClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerPickUpClip; public AnimationClipAsset playerPickUpClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerCarryIdleClip; // done public AnimationClipAsset playerCarryIdleClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerCarryWalkClip; // done public AnimationClipAsset playerCarryWalkClip;
[SerializeField] [SerializeField]
public AnimationClipAsset playerThrowClip; public AnimationClipAsset playerThrowClip;
[SerializeField] [SerializeField]
@ -72,6 +72,37 @@ public class PlayerAnimations : Script
if (!silhoBagAnimator) if (!silhoBagAnimator)
Debug.LogError("Silho Player Animator is MISSING!"); Debug.LogError("Silho Player Animator is MISSING!");
if(!playerIdleClip)
Debug.LogError("Idle clip is MISSING!");
if (!playerWalkClip)
Debug.LogError("run clip is MISSING!");
if (!playerPickUpClip)
Debug.LogError("Pickup clip is MISSING!");
if (!playerThrowClip)
Debug.LogError("Throw clip is MISSING!");
if (!playerJumpStartClip)
Debug.LogError("Jump start clip is MISSING!");
if (!playerJumpLoopClip)
Debug.LogError("Jump loop clip is MISSING!");
if (!playerJumpEndClip)
Debug.LogError("Jump end clip is MISSING!");
if (!playerCarryIdleClip)
Debug.LogError("Carry idle clip is MISSING!");
if (!playerCarryWalkClip)
Debug.LogError("Carry walk clip is MISSING!");
if (!playerRunClip)
Debug.LogError("Run clip is MISSING!");
} }
protected override void onDestroy() protected override void onDestroy()

View File

@ -83,6 +83,8 @@ public class PlayerController : Script
public GameObject silhouetteBag; public GameObject silhouetteBag;
private Renderable silhouetteBagRend; private Renderable silhouetteBagRend;
public bool playLandedAnimation { get; set; }
protected override void awake() protected override void awake()
{ {
//default setup //default setup
@ -108,8 +110,8 @@ public class PlayerController : Script
stateMachine = AddScript<StateMachine>(); stateMachine = AddScript<StateMachine>();
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>(); Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
dictionary.Add(typeof(PlayerIdleState), new PlayerIdleState(stateMachine, holdItem)); dictionary.Add(typeof(PlayerIdleState), new PlayerIdleState(stateMachine));
dictionary.Add(typeof(PlayerWalkState), new PlayerWalkState(stateMachine, holdItem)); dictionary.Add(typeof(PlayerWalkState), new PlayerWalkState(stateMachine));
dictionary.Add(typeof(PlayerRunState), new PlayerRunState(stateMachine)); dictionary.Add(typeof(PlayerRunState), new PlayerRunState(stateMachine));
dictionary.Add(typeof(PlayerJumpState), new PlayerJumpState(stateMachine)); dictionary.Add(typeof(PlayerJumpState), new PlayerJumpState(stateMachine));
dictionary.Add(typeof(PlayerFallState), new PlayerFallState(stateMachine)); dictionary.Add(typeof(PlayerFallState), new PlayerFallState(stateMachine));
@ -134,6 +136,8 @@ public class PlayerController : Script
} }
AudioHandler.audioClipHandlers["footsteps"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_footsteps"); AudioHandler.audioClipHandlers["footsteps"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_footsteps");
playLandedAnimation = false;
} }
protected override void start() protected override void start()
@ -189,6 +193,7 @@ public class PlayerController : Script
MoveKey(); MoveKey();
Sprint(); Sprint();
Jump(); Jump();
//Debug.Log($"{currentState}"); //Debug.Log($"{currentState}");
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}"); //Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}"); //Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
@ -305,12 +310,18 @@ public class PlayerController : Script
if (Input.GetKeyUp(Input.KeyCode.LeftShift)) if (Input.GetKeyUp(Input.KeyCode.LeftShift))
{ {
if (isMoveKeyPress) if (isMoveKeyPress && isGrounded)
{ {
currentState = RaccoonStates.WALKING; currentState = RaccoonStates.WALKING;
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
stateMachine.SetState(typeof(PlayerWalkState)); stateMachine.SetState(typeof(PlayerWalkState));
} }
else if(!isMoveKeyPress && isGrounded)
{
currentState = RaccoonStates.IDLE;
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
stateMachine.SetState(typeof(PlayerIdleState));
}
sprintIncreaseOnce = false; sprintIncreaseOnce = false;
moveForce = oldForce; moveForce = oldForce;
maxMoveVel = maxOldVel; maxMoveVel = maxOldVel;
@ -323,6 +334,7 @@ public class PlayerController : Script
{ {
if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad ) && isGrounded && rb != null) if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad ) && isGrounded && rb != null)
{ {
isGrounded = false;
currentState = RaccoonStates.JUMP; currentState = RaccoonStates.JUMP;
if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState)))
stateMachine.SetState(typeof(PlayerJumpState)); stateMachine.SetState(typeof(PlayerJumpState));
@ -386,6 +398,7 @@ public class PlayerController : Script
if (currentState == RaccoonStates.FALLING) if (currentState == RaccoonStates.FALLING)
{ {
currentState = RaccoonStates.LANDED; currentState = RaccoonStates.LANDED;
playLandedAnimation = true;
if (stateMachine && !stateMachine.IsState(typeof(PlayerLandState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerLandState)))
stateMachine.SetState(typeof(PlayerLandState)); stateMachine.SetState(typeof(PlayerLandState));
} }