Ray orientation

image

I’ve made a simple line of code to shoot a ray to the right of the player:

local result = workspace:Raycast(Char.HumanoidRootPart.Position, (Char.HumanoidRootPart.CFrame.RightVector * 5, MyParams)

what i’m trying to do here is figure out how to make the ray shoot to the left, instead of to the right
i’ve tried many times to learn stuff relating to cframe directions and i haven’t gotten very far

from what i can understand, i would do something similar to this:

local result = workspace:Raycast(Char.HumanoidRootPart.Position, (Char.HumanoidRootPart.CFrame.RightVector + Vector3.new(180, 0, 0)) * 5, MyParams)

but this isn’t giving me very consistent results

If you have a vector (points in some directions with some magnitude), then the negative of that vector points in the opposite direction. So the “leftVector” should just be -RightVector. In your example above, multiplying the RightVector by -5 instead of 5 should give a ray going in the other direction.

Thank you for this, CFrame isn’t really my strong suit so this helps out a lot :+1:

1 Like