I’m trying to check slopes before applying movement.
I’ve got a Vector3 that tells my player where to move.
I’m wanting to shoot out a ray from that point downward, take that hit position, shoot another ray from the player, take that position. Then compare the two positions.
But for when I shoot the rays I’m getting odd values.
void ApplyMovement()
{
var layerMask1 = 1 << 0;
var myLayerMask = layerMask1;
RaycastHit hit;
if (Physics.Raycast(movementDirection + transform.position, Vector3.down, out hit, 3f, myLayerMask))
{
movementHitPosition = hit.transform.position;
}
if (Physics.Raycast(transform.position, Vector3.down, out hit, 3f, myLayerMask))
{
playerHitPosition = hit.transform.position;
}
//GET THE SLOPE
slopeRun = Vector3.Distance(movementDirection + transform.position, transform.position);
slopeRise = playerHitPosition.y + movementHitPosition.y;
if (slope <= slopeLimit)
{
//movementDirection = new Vector3(hit.point.x, hit.point.y + (capsuleHieght * 0.5f), hit.point.z);
if (airControlToggle) myRigidbody.transform.Translate(movementDirection * Time.fixedDeltaTime * movementSpeed, Space.Self);
return;
} else {
if (airControlToggle) myRigidbody.transform.Translate(movementDirection * Time.fixedDeltaTime * movementSpeed, Space.Self);
}
}
Does anyone see what I’m doing wrong?