What I want to do is to find a way to know if there is something on the left/right of the player but for some reason, my code does not work.
Vector3 rayDirection = new Vector3();
switch (currentCameraSide)
{
case CameraSide.Left:
rayDirection = -transform.right;
break;
case CameraSide.Right:
rayDirection = transform.right;
break;
}
// Start the ray pos from the player's head
Vector3 playerStartPoint = transform.position + (transform.up * 1.5f);
// The direction of the ray (left/right)
Vector3 playerEndPoint = playerStartPoint + rayDirection;
if (Physics.Raycast(playerStartPoint, playerEndPoint, out RaycastHit raycastHitA, sideCameraRayLenght, aimColliderMask))
{
Debug.Log($"Hitting: {raycastHitA.transform.name}");
}
Basically what is happening is no matter what direction the player is facing, the direction of the hit is always left (possible world coords?)
Raycast
in the form you use it expects
you are giving it two positions ...
-> simply use the rayDirection
itself as second parameter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.