ahh, the good old deceiving software issues
- I Installed it, and will give it a test run whenever possible
On a serious note, can you recommend me an alternative solution to the ‘Mathf.Clamp’ function? I’m trying to develop a ranger’s aiming state for my own third person game, and everytime I place that function in, it messes with the ‘Tick()’ (Tick is the ‘Update()’ equivalent, but for my state machine. I’m sure you know that, just saying it if you didn’t), because whenever my player accesses the aiming function, it automatically places him on the edge of it.
I apologize if this is the wrong place for it, but can you please have a look at my state code and see if you can identify where the problem is? It’s been bothering me for 2 days now
using RPG.States.Player;
using UnityEngine;
public class PlayerRangerAimingState : PlayerBaseState
{
// MOUSE MOVEMENT AND SENSITIVITY
private float mouseX;
private float mouseY;
private float sensitivity = 100f;
// CLAMP VALUES
private float maxXRotation = 80f;
private float minXRotation = -80f;
private readonly int RangerStateBowLoadHash = Animator.StringToHash("RangerStateBowLoad");
public PlayerRangerAimingState(PlayerStateMachine stateMachine) : base(stateMachine) {}
public override void Enter()
{
stateMachine.Health.OnTakenHit += OnTakenHit; // Bug fix, when the player takes a hit
Debug.Log($"Player has entered Ranger Aiming State");
stateMachine.InputReader.RangerAimCancelEvent += CancelAim;
stateMachine.rangerAimingCamera.m_Priority = 11;
stateMachine.Animator.CrossFadeInFixedTime(RangerStateBowLoadHash, stateMachine.CrossFadeDuration);
// Capture the initial camera rotation
mouseX = stateMachine.transform.eulerAngles.y;
mouseY = stateMachine.transform.eulerAngles.x;
}
public override void Tick(float deltaTime)
{
if (stateMachine.Fighter.GetCurrentWeaponConfig().HasProjectile() && !stateMachine.Fighter.CheckForProjectileAndSufficientAmmo())
{
// (DEBATABLE IDEA) needs ammo, but no ammo in the Quiver? Switch to freelook and block aiming
stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
return;
}
if (stateMachine.InputReader.IsAttacking && !stateMachine.CooldownTokenManager.HasCooldown("RangerFiringCooldown"))
{
// Cooldown is over, and player is attempting to attack? Go back to firing arrows:
stateMachine.SwitchState(new PlayerRangerFiringState(stateMachine));
return;
}
HandleRotation(deltaTime);
Move(deltaTime);
}
public override void Exit()
{
stateMachine.Health.OnTakenHit -= OnTakenHit; // Bug fix, when the player takes a hit
Debug.Log($"IsAttacking: {stateMachine.InputReader.IsAttacking}");
Debug.Log($"Player has exited Ranger Aiming State");
stateMachine.InputReader.RangerAimCancelEvent -= CancelAim;
stateMachine.rangerAimingCamera.m_Priority = 9;
if (stateMachine.InputReader.IsAttacking)
{
// No rotation modifications will be done here, that'll just ruin everything
return;
}
else
{
// if you're not attacking, reset the y-axis euler rotation
// (because you're going back to FreeLook State, from 'CancelAim')
// Reset the y-axis rotation to zero:
Quaternion resetYRotation = Quaternion.Euler(0, stateMachine.transform.eulerAngles.y, 0);
stateMachine.transform.rotation = resetYRotation;
}
}
private void HandleRotation(float deltaTime)
{
float mouseXDelta = Input.GetAxis("Mouse X") * sensitivity * deltaTime;
float mouseYDelta = Input.GetAxis("Mouse Y") * sensitivity * deltaTime;
mouseX += mouseXDelta;
mouseY -= mouseYDelta;
// mouseY = Mathf.Clamp(mouseY, minXRotation, maxXRotation); // <-- this is the troublesome line
Quaternion targetRotation = Quaternion.Euler(mouseY, mouseX, 0);
stateMachine.transform.rotation = targetRotation;
}
private void CancelAim()
{
SetLocomotionState();
}
void OnTakenHit(GameObject instigator)
{
// Makes sure that when the player gets hit, he goes to the right state and not mess this up
// (Bug Fix)
if (stateMachine.InputReader.IsRangerAiming)
{
stateMachine.SwitchState(new PlayerRangerAimingState(stateMachine));
}
else stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
}
}
I labelled it as ‘// ← this is the troublesome line’. That would be highly appreciated 
(I tried posting this as a question in and of itself, but got no response earlier, so I figured I’d ask here)