There seems to be a bug in my code somewhere, I’ve spent over a day trying all kinds of things, and nothing seems to work. So what is happening is that I get into the jumping state, and if the surface has a positive slope, the player basically glides over the landing area until it falls off the landing area, or runs into something, and then everything goes back to normal.
Here is a link to a video of what is happening
Here is the jumping state from the Complete 3rd Person Combat System for an RPG in Unity! course
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerJumpingState : PlayerBaseState
{
private readonly int JumpHash = Animator.StringToHash("Jump");
private const float CrossFadeDuration = 0.1f;
private Vector3 momentum;
public PlayerJumpingState(PlayerStateMachine stateMachine) : base(stateMachine) { }
public override void Enter()
{
stateMachine.ForceReceiver.Jump(stateMachine.JumpForce);
momentum = stateMachine.CharacterController.velocity;
momentum.y = 0;
stateMachine.Animator.CrossFadeInFixedTime(JumpHash, CrossFadeDuration);
}
public override void Tick(float deltaTime)
{
Move(momentum, deltaTime);
// momentum.z -= deltaTime;
if(stateMachine.CharacterController.velocity.y <= 0)
{
stateMachine.SwitchState(new PlayerFallingState(stateMachine));
return;
}
FaceTarget();
}
public override void Exit()
{
}
}