Say you were casting a Ray
local RayLength = 50;
local Line = Ray.new(Origin,Direction.unit * 50)
How would I find the point that is only 30 studs down that ray?
Say you were casting a Ray
local RayLength = 50;
local Line = Ray.new(Origin,Direction.unit * 50)
How would I find the point that is only 30 studs down that ray?
Which part of the ray would you want to search 30 studs down from?
By ‘point’, do you mean the Vector3 position in the 3D world?
Yes
@goldenstein64
Clarification
Rays wouldn’t help you do this; their only purpose is to get parts that are on them. Instead, you should use CFrames. Assuming you already have an origin and direction, this should do the trick:
-- create cframe with position of origin pointing in direction
-- better way to do this without lookAt constructor?
local rotatedOrigin = CFrame.new(origin, origin + direction)
-- offset 30 studs forward
local endPoint = rotatedOrigin:ToWorldSpace(Vector3.new(0, 0, -30))
endPoint will be given as a CFrame (you can use CFrame.Position
to isolate the position Vector3). origin should be a Vector3, as should direction. This code is untested; let me know if there are issues.
Currently that code just return a point 30 studs back on the z axis.
Looking at the API reference ToWorldSpace does not have a second parameter.
I’ve edited the code slightly. Does it work now?
I’m not passing a second argument to the function at any point.
Well first of all setup a CFrame with your origin and unit vector…
CFrame.new(origin, origin+direction.Unit)
Secondly use a relative offset by multiplying a new CFrame with your 30 stud forward goal:
CFrame.new(origin, origin+direction.Unit)*CFrame.new(0, 0, -30)
Next you can use the .p or .Position component of the CFrame to get it’s vector3 position in world space.
And there you go, you’ve just done some CFrame magic.