I’m making a third-person game, where the player object will climb when it detects a wall at a certain distance, I’m using Raycast to make the detection, but I can’t find a way to make the Rigidbody climb.
My detection method
protected virtual bool DetecetOjects(LayerMask objectlayer, float detectionDistance)
{
var ray = new Ray(transform.position, transform.TransformDirection(Vector3.forward));
RaycastHit hit;
float maxDistance = detectionDistance;
LayerMask objectLayer = objectlayer;
if (Physics.Raycast(ray, out hit, maxDistance, objectLayer))
{
Debug.Log("Wall detected");
return true;
}
else
{
return false;
}
}
Jump method
//jumping
if (Input.GetKeyDown(KeyCode.Space) && onGround)
{
Jump(playerRb, playerJumpForce);
animator.SetBool("Jumping", true);
onGround = false;
//jumping towards a wall
if (DetecetOjects(enemiesLayer, detectionDistance))
{
animator.SetBool("Wall Detected", true);
}
}