Directional Roll help

So i’m trying to create a directional roll in my game, where depending on the key you are pressing, it plays a different animation and moves the character. The issue is that it is moving incorrectly, as you can see in the video
incorrect direction roll

The front roll is moving correctly, but the left and right ones seems to move the character backwards too.

this is the code

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
while character.Parent == nil do
	character.AncestryChanged:wait()
end
local hum = script.Parent.Humanoid


local rollFront = hum:LoadAnimation(script:WaitForChild("RollFront"))
local backRoll = hum:LoadAnimation(script:WaitForChild("BackRoll"))
local leftRoll = hum:LoadAnimation(script:WaitForChild("RightRoll"))
local rightRoll = hum:LoadAnimation(script:WaitForChild("LeftRoll"))


local tweenService = game:GetService("TweenService")
local Properties = {FieldOfView = 100} 
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) 
local Properties2 = {FieldOfView = 70} 

local CAS = game:GetService('ContextActionService')

local camera = game.Workspace.CurrentCamera

local velociy = 50
local velociy2 = 1000
local maxForce = 30000


local DKeyDown = false
local SKeyDown = false
local rera = true
local AKeyDown = false
local WKeyDown = false

local timeout = 0.6
local airDebounce = false
--8657156952

local keybind = Enum.KeyCode.End
local canslide = true
local DashDebounce = false
DashingDebounce = false
local HumRP = character:WaitForChild("HumanoidRootPart")
local rs = game:GetService("ReplicatedStorage")
local remoteEvent = rs.Eventos:WaitForChild("Dash")
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
local T2 = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties2)
script.WalkSpeed.Value = hum.WalkSpeed



UIS.InputBegan:Connect(function(input,gameprocessed)
	
	if gameprocessed then return end
	if canslide == true then
		if input.KeyCode == Enum.KeyCode.Q then
			if DashDebounce == false and character:FindFirstChild("Disabled") == nil then
				if rera then
					
					hum.AutoJumpEnabled = false
					
					hum.UseJumpPower = true
					DashDebounce = true

					canslide = false
					
					delay(0.3,function() -- resetar o canslide
						canslide= true
					end)
					delay(1.25,function()   -- resetar o debounce
						DashDebounce = false
						hum.JumpPower = 50
					
					end)
					
					

					local attachment = Instance.new("Attachment")
					attachment.Parent = HumRP
					if WKeyDown then
						T2:Destroy()
						T:Play()
						remoteEvent:FireServer(Vector3.new(0.411, 2.877, 2.877), Vector3.new(0, -90, -180))
						
						



						DashingDebounce = true
						rollFront:Play()

						local vectorForce = Instance.new("BodyVelocity")
						vectorForce.Parent = HumRP
						hum.JumpPower = 0
						vectorForce.MaxForce = Vector3.new(1,0,1) *30000
						vectorForce.Velocity = HumRP.CFrame.lookVector * velociy
				

						
						rera = false

						delay(timeout,function()
							DashingDebounce = false
							vectorForce:Destroy()
							rera = true
							hum.WalkSpeed = script.WalkSpeed.Value
							T2:Play()
							T:Destroy()
						end)
					end
					if DKeyDown then
						T2:Destroy()
						T:Play()
						remoteEvent:FireServer(Vector3.new(0.411, 2.877, 2.877), Vector3.new(0, -90, -180))





						DashingDebounce = true
						rollFront:Play()

						local vectorForce = Instance.new("BodyVelocity")
						vectorForce.Parent = HumRP
						hum.JumpPower = 0
						vectorForce.MaxForce = Vector3.new(30000,0,30000)
						vectorForce.Velocity = (character.HumanoidRootPart.CFrame * CFrame.Angles(0,-math.pi / 2,0)).lookVector * 50



						rera = false

						delay(timeout,function()
							DashingDebounce = false
							vectorForce:Destroy()
							rera = true
							hum.WalkSpeed = script.WalkSpeed.Value
							T2:Play()
							T:Destroy()
						end)
					end
					if AKeyDown then
						T2:Destroy()
						T:Play()
						remoteEvent:FireServer(Vector3.new(0.411, 2.877, 2.877), Vector3.new(0, -90, -180))





						DashingDebounce = true
						rollFront:Play()

						local vectorForce = Instance.new("BodyVelocity")
						vectorForce.Parent = HumRP
						hum.JumpPower = 0
						vectorForce.MaxForce = Vector3.new(30000,0,30000)
						vectorForce.Velocity = (character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.pi / 2,0)).lookVector * 50



						rera = false

						delay(timeout,function()
							DashingDebounce = false
							vectorForce:Destroy()
							rera = true
							hum.WalkSpeed = script.WalkSpeed.Value
							T2:Play()
							T:Destroy()
						end)
					end
				end
				
			end
		end
	end
end)





local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	local Player = game.Players.LocalPlayer
	local Char = Player.Character
	local Hum = Char:FindFirstChild("Humanoid")
	
	
	if hum.FloorMaterial == Enum.Material.Air then
		rera = false
	else
		rera = true
	end
	

	if UIS:IsKeyDown(Enum.KeyCode.Space) then
		rera = false
	end

	if UIS:IsKeyDown(Enum.KeyCode.W)  then
		WKeyDown = true
	else
		WKeyDown = false
	end
	if UIS:IsKeyDown(Enum.KeyCode.D)  then
		DKeyDown = true
	else
		DKeyDown = false
	end
	if UIS:IsKeyDown(Enum.KeyCode.A)  then
		AKeyDown = true
	else
		AKeyDown = false
	end
	
end)

it seems that the MaxForce in the left and right scripts are miscalculated for some reason. if someone could help me out in this one, and sorry if it’s too simple or something, im new to lua. Thanks in advance.

1 Like

If I get what you’re trying to say, you are miscalculating if the playing is going left or right by the perspective of the camera?

No. Sorry if it got you confused, but the camera doesn’t implie nothing in the script. There is miscalculations on the maxForce and i don’t know how to fix it.

If I understand correctly again, the direction of the BodyVelocity (or maxForce) is miscalculated?

Yeah, pretty much it, since the maxForce being a vector3, i can’t calculate it correctly. Btw loved ur username

Thanks!
So I would recommend checking Humanoid.MoveDirection and then applying this, and seeing which vector is the greatest, and therefore making the player move in the correct direction.

1 Like

Yeah Thank you so much i didnt know that the humanoid had this property!

1 Like