I can climb a slope but still slide off it a bit and can't climb stairs at all. I know this is mostly my code but, like I said in the title, I only want to know the logic behind why it doesn't work. Tell me if you need more parts of the code, I didn't want to put too much here.
using System.Collections.Generic;
using UnityEngine;
public class CharacterMovement : MonoBehaviour
{
//Variables
[Header("PlayerStairsClimbing")]
[SerializeField] GameObject lowerRay;
[SerializeField] GameObject higherRay;
[SerializeField] float stepHeight = 0.3f;
[SerializeField] float stepSmooth = 0.1f;
public void Awake()
{
higherRay.transform.position = new Vector3(higherRay.transform.position.x, stepHeight, higherRay.transform.position.z);
}
//Called once per fixedFrame
private void FixedUpdate()
{
//calls function
StepClimb();
}
private void StepClimb()
{
if (Physics.Raycast(transform.position - new Vector3(0, .6f, 0), orientation.transform.TransformDirection(new Vector3(0, -1, 1).normalized), .6f))
{
rb.AddForce(new Vector3(0f, 6f, 0f));
}
}
}