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