Vector math help

Hello. To make this very short and simple basically.

I need help with some vector math. How could i possibly cast a ray that originates from a LookVector(Multiplied by 100) and then point downwards(Also multiplied by 100)

This was the best way i could possibly describe what i need help with. If you didnt get it. I have some pics to hopefully give you a better picture of what i need help with.

Currently this is how my formula draws the ray. Not what i want.

local Cast = require(workspace.CastVisuals).new(Color3.new(0, 0.666667, 1),workspace)


-- Prototype code
while true do
	local Dir1 = script.Parent.CFrame.LookVector*100
	local Dir2 = -script.Parent.CFrame.UpVector*100
	local Final = Dir1+Dir2
	
	local Params = RaycastParams.new()
	Params.FilterDescendantsInstances = {workspace.A,workspace.B}
	Params.FilterType = Enum.RaycastFilterType.Exclude
	
	local Hit = Cast:Raycast(script.Parent.Position,Final,Params)
	
	if Hit then
		workspace.B.Position = Hit.Position
	end
	task.wait()
endW

This is what i actually want.

I tried using the new AI assistant/doing research before i came here for help. But i couldnt find any topics that was related to my question or just wasnt any help at all.

Im not really a “Math guy” so if anyone could help me out thatd be really appreciated and cool.

i dont think you can do this, for this you would basically need 2 rays you cant do it with a single ray.

You just have to take the diference of the Vectors:

[...]
local Diference = FinalPointObject.Position-StartPointObject.Position
local Hit = workspace:Raycast(StartPointObject,Diference, Params)
[...]

If you mean casting two rays, it’s actually quite simple.

local origin = --> the cframe

local pointA = origin * Vector3.new(0, 0, -100) --> 100 studs forward relative to the origin
local pointB = origin * Vector3.new(0, -100, -100) --> 100 studs forward and down relative to the origin

local rayA = workspace:Raycast(origin.Position, pointA - origin.Position, params) --> raycast forward
local rayB = workspace:Raycast(pointA, pointB - pointA, params) --> raycast down

if rayA or rayB then
    print("detected!")
end

Oh it was that simple. Damn now i feel actually pretty dumb :sweat_smile:

:sob: :pray: didnt i already mention you can only do this with 2 rays

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.