I'm trying to make it so that whenever the player presses the E key, they teleport 10 studs forward, but I cant figure out how to teleport them 10 studs instead of a marked area like CFrame.new(0,0,0,0)
To transport the player a few studs away from where they currently are, one could add to their Position.
1 | thing.Position = thing.Position + Vector 3. new( 10 , 0 , 0 ) |
2 | -- will transport thing ten studs in the x direction |
I'm assuming you already know how to detect when the player presses the E key so here is how you move the player(I am also assuming that you're using a local script):
1 | local player = game.Players.LocalPlayer |
2 | local Character = player.Character or player.CharacterAdded:wait() |
3 | --These are the declared variables you need-- |
4 |
5 | --- You have to use CFrame.lookVector to move in the direction the player is facing-- |
6 | player.Character.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.lookVector* 10 --Change 10 the distance you want the player to be able to teleport |
If this helps please accept the answer.
You can capture each individual coordinate like so..
1 | currentpos = humanoid.Position |
2 | x,y,z = currentpos.x, currentpos.y, currentpos.z |
3 | humanoid.Position = Vector 3. new(x+ 10 ,y,z) |
EDIT---- This is the actual logic I use to teleport a character into the air when hit by an object. Note that there is an error I get when the object does not have a cframe property.
01 | for _, object in pairs (h.Parent:GetChildren ()) do |
02 | if object.Name ~ = "Baseplate" then |
03 | if object.CFrame then |
04 | local pos = object.CFrame -- store current position |
05 | local x, y, z = pos.x, pos.y, pos.z -- store each coordinate |
06 | x, y, z = x + 0 , y + 10 , z + 0 -- add to the height coordinate |
07 | object.CFrame = CFrame.new(x,y,z) |
08 | end |
09 | end |
10 | end |