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

How can I make my laser move in the direction of the player?

I made a laser that is supposed to spawn and move the direction the player is facing when I press space. Everything else works, except the way the laser is moving.

https://gyazo.com/b13b1c237e3228991c79ac48ef534b93

As you can see, it moves to 0,0,0 for some reason. Why is this? I'm not good with CFrames so sorry if my code is really inefficient!

No errors.

local laser = Instance.new("Part")
laser.Parent = workspace.Debris
laser.Size = Vector3.new(0.6, 0.767, 3)
laser.BrickColor = BrickColor.Red()
laser.CFrame = plr.Character.PrimaryPart.CFrame
laser.Anchored = true
laser.CanCollide = false

-- code movement
local destination = plr.Character.PrimaryPart.CFrame.lookVector * 3

print(workspace:FindFirstChild(plr.Name).PrimaryPart.CFrame.lookVector)		
ds:AddItem(laser, bulletSpeed) -- ds is debris service, bulletspeed  is 0.7

local tinfo = TweenInfo.new(bulletSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local t = ts:Create(laser, tinfo, {Position = destination}) -- ts is tweenservice
t:Play()
wait(bulletSpeed)
t:Cancel()

1 answer

local destination = plr.Character.PrimaryPart.CFrame.lookVector * 3

This is a vector that describes the orientation of the player's torso as a unit vector, not it's actual position. If you want to offset the player's position by that vector, you'll have to do it explicitly, like so.

local destination = plr.Character.PrimaryPart.CFrame * (plr.Character.PrimaryPart.CFrame.lookVector * 3)

1 comment

0

It's a little better, but still not working. https://gyazo.com/689729d6db2f853165bcbbbab16f9482

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