- Home /
How can I shoot raycasts with slightly modified angles?
I am already shooting a forward raycast (indicated by blue in following picture) , but I also want to shoot a raycast angles slightly to the left and right from the transform.forward. I want to do this through script instead of creating child transforms and using those transforms' forward. How would I implement this? Here is a picture to show what I mean:
Answer by UnityedWeStand · Jul 11, 2020 at 03:24 AM
Set the direction of your raycast to be Quaternion.AngleAxis(transform.up, offsetAngle) * transform.forward
for whatever value of offsetAngle
assuming your transform's upward direction is pointing out of the screen.
Thanks, this worked. Very straightforward. Just one thing, in the Angle axis function parameters were flipped around I think.
Your answer
![](https://koobas.hobune.stream/wayback/20220613002931im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make a ray always shoot forward from Camera viewpoint. 1 Answer
raycast is pointing in two directions? 1 Answer
Problem with raycasting in direction of mouse 0 Answers
How to stop enemies from shooting each other 1 Answer
How to add slight angle/rotation variation to transform.forward? 5 Answers