this is the code I previously came up with, and, besides the fact that it just gives you a boost every time you press b on the gamepad, it wouldn't work anyways because the boost it was giving me was always in the wrong direction, unless I faced the direction it was giving me a boost in. its hard to describe but here is the code I tried.
local plyr = game.Players.LocalPlayer
while true do db=false j=0 repeat wait(.1) until plyr.Character local InputKey = "ButtonB" deb=false B1=false B=0
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:connect(function(UserInput) if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then
if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==false and B1 == false then
B=1 for i = 2,1,-1 do print (B) deb=true B1 = true if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==true and B1 == true and i>0 and B==1 then plyr.Character.Torso.Velocity=Vector3.new(50,0,0) script.S2:Play() local character = plyr.Character local animation = character.Humanoid:LoadAnimation(script.Slide) animation:Play() wait(.2) B=2 print(B) deb=false wait(.5) animation:Stop()
else B=0 B1=false deb=false end end
end
end end
end)
end
You're only applying the force to the X axis. You need to equally exert force on all 3 axi.
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.
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.
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.
local plyr = game.Players.LocalPlayer local BoostForce = 50 --50 studs/sec; changeable while true do db=false j=0 repeat wait(.1) until plyr.Character local InputKey = "ButtonB" deb=false B1=false B=0 local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:connect(function(UserInput) if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==false and B1 == false then B=1 for i = 2,1,-1 do print (B) deb=true B1 = true if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==true and B1 == true and i>0 and B==1 then plyr.Character.Torso.Velocity=Vector3.new(1,1,1)*BoostForce*plyr.Character.Torso.CFrame.lookVector --Instead of Vector3.new(1,1,1)*BoostForce you can also do Vector3.new(BoostForce,BoostForce,BoostForce) script.S2:Play() local character = plyr.Character local animation = character.Humanoid:LoadAnimation(script.Slide) animation:Play() wait(.2) B=2 print(B) deb=false wait(.5) animation:Stop() else B=0 B1=false deb=false end end end end end end) end
Hope it helps!
You can just multiply the lookVector and the BoostForce together only to make it shorter.
plyr.Character.Torso.Velocity=BoostForce*plyr.Character.Torso.CFrame.lookVector
You may use that line instead of the longer one.
local plyr = game.Players.LocalPlayer while true do db=false j=0 repeat wait(.1) until plyr.Character local InputKey = "ButtonB" deb=false B1=false B=0 local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:connect(function(UserInput) if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==false and B1 == false then B=1 for i = 2,1,-1 do print (B) deb=true B1 = true if UserInput.UserInputType == Enum.UserInputType.Gamepad1 then if UserInput.KeyCode == Enum.KeyCode[InputKey] and deb==true and B1 == true and i>0 and B==1 then plyr.Character.Torso.Velocity=Vector3.new(50,0,0) script.S2:Play() local character = plyr.Character local animation = character.Humanoid:LoadAnimation(script.Slide) animation:Play() wait(.2) B=2 print(B) deb=false wait(.5) animation:Stop() else B=0 B1=false deb=false end end end end end end) end