So what I want to do is fire a ray that goes in the direction of a gun. I’m making a modular gun script and sometimes when you import a model, the model’s rotation is off by around 90 degrees on the y axis. To fix this I have a vector value you can change called GunOrientation.
So in order to fire the ray in the direction I desire, I would use LookVector, or in this case RightVector since it has a 90 degree turn. I came up with two problems, though.
I want to keep the script as modular as possible so I shouldn’t have to worry about which vector to use.
If the rotation wasn’t a multiple of 90, and instead were something like 20 degrees then neither LookVector nor RightVector would work because the ray would cast with a 20 degree offset of where I want it. What I tried to do was multiply LookVector by 90 in this
local Direction = Gun.CFrame.LookVector * Vector3.new(Magnitude,Magnitude,Magnitude)
but obviously that wouldn’t work since that just means that it makes the ray longer. What needs to happen is the LookVector needs to swap some coordinates. So instead of being x,y,z it needs to be something like z,x,y but I don’t know how to do that. Hopefully someone can help.
I have faced this problem before especially with working with Motor6D joints, Well anything CFrame related where stuff like CFrame.lookAt fails to do it’s supposed job.
The solution I found is like your offset value however it is done by using Attachments. Attachments can also represent the offset value and you can access their WorldCframe.LookVector for the correct input and stuff. Moreover, you can insert it into the model and debug it visually more easily by rotating it using the build tools.
You don’t need joint and constraints for attachments? Just insert them into a part then use the CFrames of the attachment which is offset properly bam.