Answered by
6 years ago Edited 6 years ago
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:
1 | game.Players.PlayerAdded:Connect( function (plr) |
4 | print (plr.Character.Head.CFrame.lookVector) |
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:
01 | game.Players.PlayerAdded:Connect( function (plr) |
06 | local distanceToTravel = 50 |
07 | local xDirection = plr.Character.Head.CFrame.lookVector.X |
08 | local zDirection = plr.Character.Head.CFrame.lookVector.Z |
09 | local slope = zDirection / xDirection |
10 | local plrY = plr.Character.Torso.CFrame.Y |
11 | local plrX = plr.Character.Torso.CFrame.X |
12 | local plrZ = plr.Character.Torso.CFrame.Z |
13 | local xToGetTo = (plrX + distanceToTravel * 1 / ( 1 + slope)) or (plrX - distanceToTravel * 1 / ( 1 + slope)) |
14 | local zToGetTo = (plrZ + (slope * distanceToTravel) * 1 / ( 1 + slope)) or (plrZ - (slope * distanceToTravel) * 1 / ( 1 + slope)) |
15 | plr.Character.Torso.CFrame = CFrame.new(xToGetTo , plrY, zToGetTo) |
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