Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make an laser between the player and an part?

So, I've been trying to make a disinfection laser for my game, but it doesn't really wanna work, the size is good and I think the position too, but not the orientation. Can anyone who's good in maths take a look? I myself am not good in maths.

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		-- Ignore the API part :)
		if api.getPlayerVars(game.Players[hit.Parent.Name]).isZombie.Value == true then
			debounce = true
			
			local victimPart = hit.Parent.UpperTorso
			local part = Instance.new("Part")
			part.Parent = script.Parent.Parent
			part.Name = "Laser"
			part.Anchored = true
			part.CanCollide = false
			
			part.Position = Vector3.new((script.Parent.Parent.orb.Position.X + victimPart.Position.X) / 2,
										(script.Parent.Parent.orb.Position.Y + victimPart.Position.Y) / 2,
										(script.Parent.Parent.orb.Position.Z + victimPart.Position.Z) / 2)

			---------------- PROBLEM ----------------
			part.Orientation = Vector3.new((victimPart.Position.X / script.Parent.Parent.orb.Position.X) * 90,
										(victimPart.Position.Y / script.Parent.Parent.orb.Position.Y) * 90,
										(victimPart.Position.Z / script.Parent.Parent.orb.Position.Z) * 90)
			---------------- PROBLEM ----------------

			local lengthX = victimPart.Position.X - script.Parent.Parent.orb.Position.X
			local lengthY = victimPart.Position.Y - script.Parent.Parent.orb.Position.Y
			local lengthZ = victimPart.Position.Z - script.Parent.Parent.orb.Position.Z
			local length = math.sqrt(math.pow(lengthX, 2) + math.pow(lengthY, 2) + math.pow(lengthZ, 2))
			
			part.Size = Vector3.new(1.25, 1.25, length)
			part.Transparency = .25
			part.Color = Color3.new(0, 1, 0)
			
			part.Material = Enum.Material.SmoothPlastic
			part.BackSurface = Enum.SurfaceType.Smooth
			part.BottomSurface = Enum.SurfaceType.Smooth
			part.FrontSurface = Enum.SurfaceType.Smooth
			part.LeftSurface = Enum.SurfaceType.Smooth
			part.RightSurface = Enum.SurfaceType.Smooth
			part.TopSurface = Enum.SurfaceType.Smooth
			
			wait(3)
			--part:Destroy()
			debounce = false
		end
	end
end)

4 comments

0

A lot of the math here can be done within Roblox itself

0

(victimPart.Position - script.Parent.Parent.orb.Position).Magnitude

0

ok, but then is the orientation a problem.

0

changing the Position, Orientaion, or Size causes the part to do this stupid gimmick where it changes its position so that its not colliding with anything, use Part.CFrame = CFrame.new(Vector3 Position)*CFrame.fromEulerAnglesXYZ(XAxis,YAxis,ZAxis), fromEulerAnglesXYZ uses radians, i hate this weird gimmick

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.