- Home /
Raycast in the direction of looking plus an angle offset
Hello, I'm trying to add a recoil system to my simple FPS, till now when I shot a gun I was raycasting using
Vector3 dir = playerCamera.transform.forward;
ray = new Ray(playerCamera.transform.position, dir);
(playerCamera being camera attached to the player), and it worked just fine, but now every time I shoot I am using a script to calculate an angle to which the gun lerps. The script then returns an angle (float value) which I want to add to the raycast direction (just so the gun shoots where it's pointing). I went through quite a few topics on that but couldn't find anything that would work, I have tried lots of things myself (like multiplying the forward vector by Quaternion.AngleAxis) and
Vector3 dir = Quaternion.Euler(recoil,0,0) * playerCamera.transform.forward;
ray = new Ray(playerCamera.transform.position, dir);
(which almost works), but I always have the same problem - it only works in one direction, when I look left it shoots to the left instead of up - I belive it's got to do with local / global rotation, but couldn't fihure it out myself. Thank you for any help on the topic.
Your answer
Follow this Question
Related Questions
Door script using Raycast 1 Answer
Raycasting at an offset angle? 4 Answers
How to raycast using a vector3 and a rotation? 1 Answer
Raycast across angle? 3 Answers
Problem With Raycasthit Angle 0 Answers