I have a couple more issues i’ve discovered with some playtesting, figured better to reply here instead of open another topic since they are still odd camera behaviors. I’ve pinned down the source of the first issue at least, but i’m unsure of how i would go about fixing (or debugging) it.
- If I am target locked and cancel the target to go back to free look while I am moving backwards directly towards the camera while using the ease in(or out or in/out) for the default blend the camera will spin extremely fast over the duration of the blend before settling in the correct location. If i use cut for the default blend it doesn’t do this so it is definitely something to do with using the blend reacting poorly to something else, but having ease value is very nice and improves feel substantially so i would like to figure out why.
Clip demonstrating: https://imgur.com/a/pO0wUDw
- When i switch back and forth between targeting and free look while moving backwards directly towards the camera the position of the free look camera is oddly offset from where it is expected to be, it works as expected moving in any other direction (seemingly including back-right/back-left) reliably reaching the same position with multiple toggles.
Clip demonstrating: https://imgur.com/a/UYrY1MK
Since they both only occur when the character is running towards the camera logically it would seem that they are linked to the same source issue, but where that source is i can’t seem to find. I’ve combed through basically every parameter for the cameras and can’t find a seemingly relevant setting except maybe the Heading Definition but none of the options make a difference. I have a feeling it has to do with calculate movement in the freelookstate, but i don’t understand the relation between the camera and the movement well enough to pin it down.
My free look cam:
My State Driven cam:
And my freelookstate script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class PlayerFreeLookState : PlayerBaseState
{
private readonly int FreeLookBlendTreeHash = Animator.StringToHash("FreeLookBlendTree");
private readonly int FreeLookSpeedHash = Animator.StringToHash("FreeLookSpeed");
private const float AnimatorDampTime = 0.1f;
private const float CrossFadeDuration = .1f;
private Vector2 dodgingDirectionInput;
private float remainingDodgeTime;
public PlayerFreeLookState(PlayerStateMachine stateMachine) : base(stateMachine) { }
public override void Enter()
{
stateMachine.InputReader.TargetEvent += OnTarget;
stateMachine.InputReader.JumpEvent += OnJump;
stateMachine.InputReader.DodgeEvent += OnDodge;
stateMachine.Animator.CrossFadeInFixedTime(FreeLookBlendTreeHash, CrossFadeDuration);
}
public override void Tick(float deltaTime)
{
if (stateMachine.InputReader.IsAttacking)
{
stateMachine.SwitchState(new PlayerAttackingState(stateMachine, 0));
return;
}
Vector3 movement = CalculateMovement();
Move(movement * stateMachine.FreeLookMovementSpeed, deltaTime);
if (stateMachine.InputReader.MovementValue == Vector2.zero)
{
stateMachine.Animator.SetFloat(FreeLookSpeedHash, 0, AnimatorDampTime, deltaTime);
return;
}
stateMachine.Animator.SetFloat(FreeLookSpeedHash, 1, AnimatorDampTime, deltaTime);
FaceMovementDirection(movement, deltaTime);
}
private void OnTarget()
{
if (!stateMachine.Targeter.SelectTarget()) { return; }
stateMachine.SwitchState(new PlayerTargetingState(stateMachine));
}
private void OnDodge()
{
if (stateMachine.InputReader.MovementValue == Vector2.zero) { return; }
stateMachine.SwitchState(new PlayerDodgingState(stateMachine, stateMachine.InputReader.MovementValue, null));
}
private void OnJump()
{
stateMachine.SwitchState(new PlayerJumpingState(stateMachine));
}
private Vector3 CalculateMovement()
{
Vector3 movement = new Vector3();
Vector3 forward = stateMachine.MainCameraTransform.forward;
Vector3 right = stateMachine.MainCameraTransform.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
movement = forward * stateMachine.InputReader.MovementValue.y + right * stateMachine.InputReader.MovementValue.x;
return movement;
}
private void FaceMovementDirection(Vector3 movement, float deltaTime)
{
stateMachine.transform.rotation = Quaternion.Lerp(
stateMachine.transform.rotation,
Quaternion.LookRotation(movement),
deltaTime * stateMachine.RotationDamping);
}
public override void Exit()
{
stateMachine.InputReader.TargetEvent -= OnTarget;
stateMachine.InputReader.JumpEvent -= OnJump;
stateMachine.InputReader.DodgeEvent -= OnDodge;
}
}