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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Abandion 118
4 years ago
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)
0
It's a little better, but still not working. https://gyazo.com/689729d6db2f853165bcbbbab16f9482 MakeYourEscape 334 — 4y
Ad

Answer this question