Only Get the horizontal plane of lookVector?
I'm making a script where when you double tap the "w" key, you get propelled at the direction your camera is facing. I only want it to propel you in a horizontal direction, (x and z) and not a vertical direction (y). (All the code is in a LocalScript inside of StarterCharacter Scripts) Here is my Code so far:
02 | game.Players.PlayerAdded:connect( function (player) |
03 | script.LocalScript:clone().Parent = player.CharacterAdded:wait() |
08 | local cam = workspace.CurrentCamera |
09 | local player = game.Players.LocalPlayer |
10 | local Char = player.Character |
11 | local Humanoid = Char:WaitForChild( "Humanoid" ) |
12 | local Mouse = player:GetMouse() |
15 | local Trail = game.ServerStorage.Trail:Clone() |
16 | local Mouse = player:GetMouse() |
26 | Mouse.KeyDown:connect( function (key) |
27 | if not enabled and clicked then |
30 | if key = = "w" and _G.Energy > = 25 then |
33 | local function onTap() |
34 | if tick() - lastTapTime < 0.2 then |
35 | print ( "double Click!" ) |
38 | player.Character.UpperTorso.Velocity = cam.CFrame.lookVector * 300 |
39 | Trail.Parent = Char.HumanoidRootPart |
40 | local attachment 0 = Instance.new( "Attachment" , Char.Head) |
41 | attachment 0. Name = "TrailAttachment0" |
42 | local attachment 1 = Instance.new( "Attachment" , Char.HumanoidRootPart) |
43 | attachment 1. Name = "TrailAttachment1" |
44 | Trail.Attachment 0 = attachment 0 |
45 | Trail.Attachment 1 = attachment 1 |
48 | _G.Energy = _G.Energy - 25 |
I'd also like to point out that this script doesnt work when I publish the game, and play it from the site. Any solutions are greatly appreciated!!