Skip to content

Instantly share code, notes, and snippets.

@IJEMIN
Created January 20, 2018 12:07
Show Gist options
  • Save IJEMIN/d62b2d85816bedf7c80b810cd57e5f55 to your computer and use it in GitHub Desktop.
Save IJEMIN/d62b2d85816bedf7c80b810cd57e5f55 to your computer and use it in GitHub Desktop.
How to Raycast by Angle in Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayByAngle : MonoBehaviour {
public float angle;
public float distance = 1f;
// Update is called once per frame
void Update () {
ShootRay();
}
void ShootRay()
{
var direction = Quaternion.AngleAxis(angle, transform.right) * transform.forward;
Ray ray = new Ray(transform.position,direction);
Debug.DrawLine(ray.origin,ray.origin + ray.direction * distance,Color.red);
if(Physics.Raycast(ray,distance))
{
Debug.Log("Something is there");
}
}
}
@IJEMIN
Copy link
Author

IJEMIN commented Dec 21, 2022

@Valignus I'm Glad it helped! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment