I want the ray to face down but i cant seem to do it heres what i have so far
local ray = Ray.new(tool.Handle.CFrame.p, CFrame.new(0,tool.Handle.CFrame.y.unit*10,0))
I want the ray to face down but i cant seem to do it heres what i have so far
local ray = Ray.new(tool.Handle.CFrame.p, CFrame.new(0,tool.Handle.CFrame.y.unit*10,0))
To make the code readable and not trying to jumble it up all on one line, you need to get the direction of the bottom surface of the the tool is facing.
The supported API for turning an object-space direction (the downward direction) to a world-space direction, is as follows:
CFrame :vectorToWorldSpace(Vector3)
So, what is the direction of "down" in the world-space? It is:
Vector3.new(0,1,0)
Let's use that as our object-space. In object-space, that vector always points down no matter how it's rotated. So we do this to get the downward direction, no matter the rotation, from object-space to world-space.
local DownVector = tool.Handle.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0))
Now, combine that code with what you have to get the ray to face down - no matter how the handle is facing:
local DownVector = tool.Handle.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0))
local ray = Ray.new(tool.Handle.CFrame.p, DownVector)
EDIT Fixed downward vector direction
The positive y-axis corresponds to up in the world space, not down, hence the vector should be (0,-1,0).
Don't you think you could get the laser to point downwards just by giving it Vector3.new(0, -1 , 0) for the direction?
Wow thanks :D
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
The lua code thing isnt working sorry :l
Did you put the code in between the two lines of ~~~~~~ ?
yeah
You have to leave to ~~~~~~~~ each on their own line. Then just put the code between
Highlight your code, and just click the blue Lua button.
I fixed it for you.