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

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:

--Getting the Camera
	game.Players.PlayerAdded:connect(function(player)
		script.LocalScript:clone().Parent = player.CharacterAdded:wait()
	end)	


--Local Variables	
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")
local Mouse = player:GetMouse()
local lastTapTime = 0
local clicked = false
local Trail = game.ServerStorage.Trail:Clone()
local Mouse = player:GetMouse()


_G.Energy = 100



--Moving the Humanoid
	--Double Tap
enabled = true
Mouse.KeyDown:connect(function(key)
    if not enabled and clicked then
        return
    end
    if key == "w" and _G.Energy >= 25 then
    enabled = false
 
    local function onTap()
        if tick() - lastTapTime < 0.2 then
            print("double Click!")
            clicked = true
				--What happends when the user double taps
			player.Character.UpperTorso.Velocity = cam.CFrame.lookVector * 300
			Trail.Parent = Char.HumanoidRootPart
			local attachment0 = Instance.new("Attachment", Char.Head)
			attachment0.Name = "TrailAttachment0"
			local attachment1 = Instance.new("Attachment", Char.HumanoidRootPart)
			attachment1.Name = "TrailAttachment1"
			Trail.Attachment0 = attachment0
			Trail.Attachment1 = attachment1
			wait(0.3)
			Trail:Remove()
			_G.Energy = _G.Energy - 25
			wait(0.5)   
            end
        end
 
        onTap()
        lastTapTime = tick()
 
        wait(0.5)
        enabled = true
        clicked = false
    end
end)

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!!

3 comments

0

v3*Vector3.new(1,0,1) would flatten it to horizontal.

0

So I would put that after cam.CFrame.LookVector? Sorry for late responce

0

Wait i got it, thanks so much!

1 answer

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