Hi everyone,
I’m slowly integrating bits and pieces of the RPG course into the 3rd Person course. Working really well so far, and I’ve ‘almost’ got all of the features I need working fine. I just can’t quite figure out the last piece of the Ability puzzle.
I’m using the ActionStore to handle which ActionItem is currently equipped (listening for numeric key input in the new input system).
[SerializeField] Dictionary<ActionItem, bool> unlockedAbilities = new Dictionary<ActionItem, bool>();
public Ability[] abilities;
[SerializeField] ActionItem currentlyEquippedActionItem = null;
And the ‘Use’ method is where I switch state (this is called from my State Machine states)
public bool Use(GameObject user)
{
if (currentlyEquippedActionItem)
{
playerStateMachine.SwitchState(new PlayerUseAbilityState(playerStateMachine, currentlyEquippedActionItem));
return true;
}
return false;
}
So after the press the UseAbility input, the player switches to the UseAbility State:
using EchoesOfEight.Abilities;
using EchoesOfEight.Inventories;
using System;
using UnityEngine;
namespace EchoesOfEight.Control
{
public class PlayerUseAbilityState : PlayerBaseState
{
private ActionItem ability;
public PlayerUseAbilityState(PlayerStateMachine stateMachine, ActionItem ability) : base(stateMachine)
{
this.ability = ability;
}
public override void Enter()
{
Debug.Log("Entered use ability state");
stateMachine.InputReader.UseAbilityEvent -= OnUseAbility; // Prevent triggering another ability
ability.Use(stateMachine.gameObject);
}
private void OnUseAbility()
{
}
public override void Tick(float deltaTime)
{
Vector3 movement = CalculateMovement();
}
public override void Exit()
{
Debug.Log("Exited UseAbulity State");
}
private Vector3 CalculateMovement()
{
Vector3 forward = stateMachine.MainCameraTransform.forward;
Vector3 right = stateMachine.MainCameraTransform.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
return forward * stateMachine.InputReader.MovementValue.y +
right * stateMachine.InputReader.MovementValue.x;
}
private void FaceMovementDirection(Vector3 movement, float deltaTime)
{
stateMachine.transform.rotation = Quaternion.Lerp(
stateMachine.transform.rotation,
Quaternion.LookRotation(movement),
deltaTime * stateMachine.RotationDamping);
}
private void OnAbilityDeactivated()
{
Debug.Log("Returned to Locomotion");
ReturnToLocomotion();
}
}
}
And hangs there forever (which is to be expected!) So, my question is:
How can I use the ReturnToLocomotion function in the useability state? Or in other words, how can that state know when all of the strategies are finished doing their thing?
I’m watching the lectures again to see if I can make use of the finish() event in each strategy, but a point in the right direction would be much appreciated!
Edit to add:
I initially just had the ability be triggered in the Free look/Targeting states, and this worked fine and dandy, but I’m hoping to be able to do more with it in a dedicated useability state