Laser go toward the look vector?

Hello,
I’m trying to make a laser that goes toward the look vector.
Screenshot:
Screenshot 2021-11-07 105356
Script of what I have now:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player)
	local Character = Player.Character
	
	local Projectile = Instance.new("Part")
	Projectile.Parent = workspace
	Projectile.Name = "Projecitle"
	Projectile.Position = Character.Direction.Position + Character.Direction.CFrame.LookVector
	Projectile.Size = Character.Direction.Size + Character.Direction.CFrame.LookVector * Vector3.new(1,1,1)
	Projectile.Material = Enum.Material.Neon
	Projectile.Color = Color3.new(0.470588, 0.313725, 0)
end)
1 Like

So you want to make a raycasting laser that will shoot out of the look vector?

1 Like

I made a small reply on your previous thread (but I guess the question you asked was supposed to be on a different thread), so I’ll elaborate on my solution:

MidPoint is simply the middle Vector3 between where you shoot the laser and the end of the laser.

CFrame.new with 2 Vector3s positions an object at the first Vector3 provided (midPoint is the first Vector3 in the quote above). Then, it rotates the object so much so that the front face of the object faces towards the second Vector3 provided (aimDirection * range in the quote above).

Because you’re making the part look at the place you’re shooting, you will need to resize the front face of the object so it extends in the correct direction (to resize the front face, resize on the Z axis). We resize with the Z axis as range because that’s how long the laser is.

I know your solution worked. This is something different. I’m trying two methods one with raycast and one without to learn different ways to do something. It’s not particularly for a game so I just want to practice.

only look at CFrame.lookAt
:sweat_smile:

How can I make this go toward the look vector? Sorry I’m kind of new to this. :sweat_smile:

For endPosition, you need to change to HumanoidRootPart.CFrame.LookVector*1000

:sweat_smile:

1 Like