Instead of just making the player go really fast, I want to actually teleport a player based on their camera's lookVector. Maybe like 50 studs or so. All my code so far is in a local script inside of StarterGui. How would make this change? Any help is appreciated!
--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 * Vector3.new(1,0,1) * 400 -- This is the part I want to change. 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) --[[--[[Double Jump enabled = true Mouse.KeyDown:connect(function(key) if not enabled and clicked then return end if key == " " and _G.Energy >= 12.5 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 = Vector3.new(0, 100, 0) 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 - 12.5 wait(1) end end onTap() lastTapTime = tick() wait(0.5) enabled = true clicked = false end end) --Repleneshing Energy for i = 1, math.huge do wait(0.1) print(_G.Energy) if _G.Energy < 100 then _G.Energy = _G.Energy + 12.5 print(_G.Energy) wait(2) end end ]]--]]
I don't completely understand cframes yet so forgive me for not giving a script answer. I think what would work is if you got the lookVector
of the player. then teleported them in that direction by setting their CFrame + 50(in the direction the player was looking) leaving all the other parts of the CFrame teleport the same. I hope this helps. Sorry if I am a bit unclear. Have a great day scripting!
Edit 1.
This script prints which way the player is looking:
game.Players.PlayerAdded:Connect(function(plr) wait(5) while wait(1) do print(plr.Character.Head.CFrame.lookVector) end end)
I am guessing you dont want the player to teleport up and down so ignore the y axis when teleporting. I will continue to look for an answer but I hope this helps a little
Edit 2.
Sorry I just dont know enough about CFrames yet to be much help. However there are a couple of helpful resources I can direct you to and some script I tried that you can fiddle with(doesnt work as of now). Here is a link
I hope will help you understand the script I wrote and the problem you are facing. Here is the script I tried:
game.Players.PlayerAdded:Connect(function(plr) wait(2) while wait(2) do local distanceToTravel = 50 local xDirection = plr.Character.Head.CFrame.lookVector.X local zDirection = plr.Character.Head.CFrame.lookVector.Z local slope = zDirection / xDirection local plrY = plr.Character.Torso.CFrame.Y local plrX = plr.Character.Torso.CFrame.X local plrZ = plr.Character.Torso.CFrame.Z local xToGetTo = (plrX + distanceToTravel * 1 / (1 + slope)) or (plrX - distanceToTravel * 1 / (1 + slope)) local zToGetTo = (plrZ + (slope * distanceToTravel) * 1 / (1 + slope)) or (plrZ - (slope * distanceToTravel) * 1 / (1 + slope)) plr.Character.Torso.CFrame = CFrame.new(xToGetTo , plrY, zToGetTo) end end)
there are a couple problems one of which is: what if slope = inf/undefined. Hope this helps you find the answer. If you find the answer please comment that you did and post it in the question so that I can see it. Have a great day scripting, Plegethon5778