# Is there a way to turn LookVector into RightVector via script?

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.

``````GunOrientation = CFrame.Angles(0,math.rad(90),0)
``````

That makes it go from A to B

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.

1. I want to keep the script as modular as possible so I shouldn’t have to worry about which vector to use.

2. 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.

https://streamable.com/q9chu2

https://streamable.com/gcft3e

(The rod constraints model rays)

I guess I’ll try quickly switching it back to it’s original position, fire the ray, then get it back in it’s original position.

1 Like

this is where i personally learned on how to use it

1 Like

I see what you’re trying to say but I’m not sure about how I would implement it. Is it possible that you could tell me how to?

This works but I feel like it’s a cheap way out of it. I’ll mark it as the solution for now but hopefully someone can answer me.

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.

Yeah attachments are real usefull.

2 Likes
``````     SOME_CFRAME.LookVector:Cross(SOME_CFRAME_UpVector)
--that's how you would implement it
``````

NOTE THE `CFrames` ARE THE SAME

1 Like

also don’t say this topics solved bc less people will click it

I still don’t get how this would help me apply an offset in degrees.

I wish I could but I’m not using joints or constraints. I only used the rod constraints to tell you where the ray was.

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.

Alright, I’m trying that out right now.

I see. You just create an attachment that has it’s own CFrame and alter that LookVector, and then simulate that with a part. Thank you, it worked.