Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Raycast not faceing downward?

Asked by 9 years ago

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))

0
The lua code thing isnt working sorry :l xXUltraAltraXx 20 — 9y
0
Did you put the code in between the two lines of ~~~~~~ ? M39a9am3R 3210 — 9y
0
yeah xXUltraAltraXx 20 — 9y
0
You have to leave to ~~~~~~~~ each on their own line. Then just put the code between Perci1 4988 — 9y
View all comments (2 more)
0
Highlight your code, and just click the blue Lua button. DigitalVeer 1473 — 9y
0
I fixed it for you. MrNicNac 855 — 9y

1 answer

Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
9 years ago

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

1
The positive y-axis corresponds to up in the world space, not down, hence the vector should be (0,-1,0). duckwit 1404 — 9y
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? Perci1 4988 — 9y
0
Wow thanks :D xXUltraAltraXx 20 — 9y
Ad

Answer this question