What I’m saying for anyone confused: I’m trying to make it so no matter what orientation the part is, the raycast will always stay the same end position.
Example: A raycast will always look down by -2 studs and when the orientation changes, I want it to stay looking down -2 studs instead of getting messed up.
Is this possible?
I think your raycast might be using object space, which means that the “down” direction is relative to the orientation of the object versus like the world (where you need to use world space)
Your question does not solidify its stance on what “locking an end position” means with respect to an object’s orientation. There are two interpretations of your question:
- The raycast should always cast downwards with respect to the object’s sense of down.
- The raycast should always cast downwards regardless of the object’s orientation.
If your goal is to achieve interpretation #1, then you’ll need to cast the ray in object space. This is achieved by sourcing the object’s local down vector, which is the inverse of its CFrame’s “UpVector”:
local pivot = assembly:GetPivot()
local result = workspace:Raycast(pivot.Position, pivot.UpVector * -STUDS)
If your goal is to achieve interpretation #2, then you’ll need to cast the ray in world space. This is achieved by sourcing the cardinal Y-axis unit vector stored as constant on the Vector3 class:
local pivot = assembly:GetPivot()
local result = workspace:Raycast(pivot.Position, Vector3.yAxis * -STUDS)
1 Like