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

Using FindPartOnRay does not return a vector3?

Asked by 4 years ago
Edited 4 years ago

I've done raycasting before, and it's worked using the same method that I'm doing now -- pretty much a copy off of the Wiki on it. Except the output says that the intersection isn't a vector3 but an object?

local ray = Ray.new(thisUnit.Torso.Position, (v.Torso.Position - thisUnit.Torso.Position).Unit * 10)
local hit, endPoint = workspace:FindPartOnRay(ray, thisUnit, false, true)
print(hit)
print(endPoint)

Printing endPoint does return a vector3 value, that's good. So after that I make a part for this ray, and use CFrame so that the ray begins and ends between these two parts.

beam.CFrame = CFrame.new(thisUnit.Torso.Position, endPoint) * CFrame.new(0, 0, -(thisUnit.Torso.Position - hit).Magnitude/2)

The output returns this:

02:19:07.691 - Workspace.lightInfantry.scripts.attackScript:29: bad argument #2 to '?' (Vector3 expected, got Object)

Does anyone have any clues why? Or what I should do?

1 answer

Log in to vote
0
Answered by 4 years ago

The first value that FindPartOnRay returns is the part that was hit, or nil.

You wrote -(thisUnit.Torso.Position - hit).Magnitude

You are trying to subtract a vector3 position from the object, rather than the objects position.

Did you mean to write -(thisUnit.Torso.Position - hit.Position).Magnitude instead?

0
Now I feel like an idiot for missing that. It worked and I'm grateful for the answer. I find your name to be very fitting too! radiant_Light203 1166 — 4y
2
ur not idiot royaltoe 5144 — 4y
Ad

Answer this question