Hey, I’m trying to add a rolling mechanic to my game. I want the player to be able to “side roll” when the “locked” variable is set to true (in a different script) based on whether they are holding A or D. I just don’t know how to start though. here is my script
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.C then
if debounce == false and locked == false then
print("hello locked = false")
debounce = true
roll:Play()
HRP.Velocity = HRP.CFrame.lookVector*150
wait(1)
debounce = false
elseif debounce == false and locked == true then
if UIS.IsKeyDown(Enum.KeyCode.A) then
-- where the script for right rolling should go
elseif UIS.IsKeyDown(Enum.KeyCode.D) then
-- where the script for left rolling should go
end
end
end
end)
I tried doing HRP.Velocity = Vector3.new(150, 0 , -150) but it didnt work very consistently. If anyone who knows more about velocity than me can help, it would be a great service to me. Thanks in advance!
Looking at older posts but
You could assign a BodyVelocity so that it will keep moving in a consistent direction to whatever the HRP
variable is (Assuming it’s a BasePart of some sort)
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.C then
if debounce == false and locked == false then
print("hello locked = false")
debounce = true
roll:Play()
HRP.Velocity = HRP.CFrame.lookVector*150
wait(1)
debounce = false
elseif debounce == false and locked == true then
if UIS.IsKeyDown(Enum.KeyCode.A) then
--NEW STUFF--
local RightVelocity = Instance.new("BodyVelocity")
RightVelocity.MaxForce = Vector3.new(math.huge, math.huge, math,huge) --This just basically prevents it from slowing down at all if you want it to move at a constant speed
RightVelocity.Velocity = Vector3.new(150, 0, 0) --Or wherever right is
elseif UIS.IsKeyDown(Enum.KeyCode.D) then
local LeftVelocity = Instance.new("BodyVelocity")
LeftVelocity.MaxForce = Vector3.new(math.huge, math.huge, math,huge)
LeftVelocity.Velocity = Vector3.new(-150, 0, 0)
-- Same thing for the LeftVelocity as well
end
end
end
end)
I was actually able to fix this problem by using the RightVector property of CFrame. I was about to mark this problem as solved. This solution works as well though!