Answered by
8 years ago Edited 8 years ago
What's the issue?
You're only applying the force to the X axis. You need to equally exert force on all 3 axi.
lookVector
lookVector
, a property of CFrame, can return the forward direction that a part is facing. It returns a 1 if it's fully facing an axis or -1 if they're facing the negative side of the axis and it can also return all the numbers in between. It can do this to any axis.
1 | print (workspace.Part.CFrame.lookVector) |
1,0,0.84
This part is facing towards the positive X and a little bit towards the positive Z axis.
Final Product
We can do arithmetic with this. I made a new variable called BoostForce
which is the max velocity something can move in all directions. In this case I made it 50, you can edit it. I multiplied BoostForce with Vector3.new(1,1,1)
to get Vector3.new(50,50,50)
. Then I multiplied that with the lookvector to get a percentage(1 is 100%, 0.84 is 84% and etc...). If I were to use the part from the last chapter I can multiply the last part's lookVector
with Vector3.new(50,50,50)
to get: Vector3.new(50,0,42)
which is what the part's velocity will be.
01 | local plyr = game.Players.LocalPlayer |
07 | repeat wait(. 1 ) until plyr.Character |
08 | local InputKey = "ButtonB" |
13 | local UserInputService = game:GetService( "UserInputService" ) |
15 | UserInputService.InputBegan:connect( function (UserInput) |
16 | if UserInput.UserInputType = = Enum.UserInputType.Gamepad 1 then |
18 | if UserInput.KeyCode = = Enum.KeyCode [ InputKey ] and deb = = false and B 1 = = false then |
29 | if UserInput.UserInputType = = Enum.UserInputType.Gamepad 1 then if UserInput.KeyCode = = Enum.KeyCode [ InputKey ] and deb = = true and B 1 = = true and i> 0 and B = = 1 then |
32 | plyr.Character.Torso.Velocity = Vector 3. new( 1 , 1 , 1 )*BoostForce*plyr.Character.Torso.CFrame.lookVector |
36 | local character = plyr.Character |
38 | local animation = character.Humanoid:LoadAnimation(script.Slide) |
Hope it helps!
Edit:
You can just multiply the lookVector and the BoostForce together only to make it shorter.
1 | plyr.Character.Torso.Velocity = BoostForce*plyr.Character.Torso.CFrame.lookVector |
You may use that line instead of the longer one.