Im making a script where a player can thrust forward in the direction he/she is facing. The only problem is that i can't find the direction the player is facing.
01 | local Player = game.Players.LocalPlayer |
02 | Mouse = Player:GetMouse() |
03 | local canJump = true |
04 | local facing = Player.Character.Torso |
05 |
06 | Mouse.KeyDown:connect( function (Key) |
07 | if (Key:lower() = = "f" ) and canJump = = true then |
08 | canJump = false |
09 | Player.Character.Torso.Velocity = Vector 3. new( 0 , 115 , 200 ) --How high Player jumps |
10 | wait( 3 ) |
11 | canJump = true |
12 | end |
13 | end ) |
01 | local speed = 100 |
02 |
03 | local root = Player.Character:WaitForChild( "HumanoidRootPart" ) --R15 does not have a torso |
04 | local thrust = Instance.new( "BodyVelocity" ,root) |
05 | thrust.MaxForce = Vector 3. new( 100000 , 100000 , 100000 ) |
06 |
07 | local target = (root.CFrame * CFrame.new( 0 , 0 ,- 200 )) + Vector 3. new( 0 , 115 , 0 ) |
08 | thrust.Velocity = (target.p - root.CFrame.p).unit * speed |
09 | wait( 2 ) |
10 | thrust:Destroy() |
If you want another approach where they can move freely then do this
1 | local human = Player.Character:WaitForChild( "Humanoid" ) |
2 | human.WalkSpeed = 30 |
3 | human.JumpPower = 80 |
4 | human.Jump = true |
5 | wait( 1 ) |
6 | human.WalkSpeed = 16 |
7 | human.JumpPower = 50 |
If the above solution works, but is too powerful, I'mma add onto it. Excuse me if I'm supposed to comment instead, but it is a solution.
Instead of using the Velocity property which is known for it's wild sporadic behavior, use BodyThrust. It's built into ROBLOX. It's very similar to any of the other BodyMover classes (Because it is one.)