Hello,
I am having a problem that I am trying to send a raycast out from the player to check if the player is touching a wall. The raycast works correctly but not in the right direction. The raycast is coming from the player and I’m using orientation.forward with a rotating transform called orientation to determine the direction of the ray. When I draw the ray on screen, the ray always points in the same direction. I can also confirm that the object that is determining the direction of the ray is turning but the ray is not.
Thanks
Here is the relevant code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Climbing : MonoBehaviour
{
public Transform orientation;
public LayerMask whatIsWall;
public float detectionLength;
public float sphereCastRadius ;
private RaycastHit frontWallHit;
private bool wallFront;
private void Update()
{
WallCheck();
}
private void WallCheck()
{
wallFront = Physics.SphereCast(transform.position, sphereCastRadius, orientation.forward, out frontWallHit, detectionLength, whatIsWall); }
In the editor, detectionlength = 0.7, and spherecast radius = 0.25
Orientation is an object that rotates on the y axis. It is basically the camera rotation but only on the y axis. Also, the wall I’m trying to detect with this code has the what is wall layer mask. This isn’t the full script, but it the part with the problem and everything that relates to that.
Finally, I meant spherecast, not raycast in the original description.