So I was trying to make a car movement script for all devices and this happened: when the player moved left/right while moving forward/backwards it stopped the car completely, the reason why was because the script did not know whether i was moving forwards/backwards or right/left because the direction was in the middle of both of them, now i want to get the horizontal and vertical movement (in numbers). Here's the failed script:
while true do wait() if script.Parent.Occupant then local camera = game.Workspace.CurrentCamera local humanoid = script.Parent.Occupant -- fill this in with your valid humanoid if (humanoid.MoveDirection:Dot(script.Parent.CFrame.LookVector) > 0.75) then -- we're going right print("movefor") script.Parent.Velocity = script.Parent.Velocity + script.Parent.CFrame.LookVector * 5 elseif (humanoid.MoveDirection:Dot(script.Parent.CFrame.LookVector) < -0.75) then -- we're going right print("movebac") script.Parent.Velocity = script.Parent.Velocity + script.Parent.CFrame.LookVector * -5 end if (humanoid.MoveDirection:Dot(script.Parent.CFrame.RightVector) > 0.75) then -- we're going right print("turningright") script.Parent.Velocity = Vector3.new(0,0,0) if script.Parent.RotVelocity ~= script.Parent.CFrame.UpVector * -10 then script.Parent.RotVelocity = script.Parent.CFrame.UpVector * -10 end script.Parent.Velocity = script.Parent.Velocity + script.Parent.CFrame.LookVector * 5 elseif (humanoid.MoveDirection:Dot(script.Parent.CFrame.RightVector) < -0.75) then -- we're going left print("turningleft") script.Parent.Velocity = Vector3.new(0,0,0) if script.Parent.RotVelocity ~= script.Parent.CFrame.UpVector * 10 then script.Parent.RotVelocity = script.Parent.CFrame.UpVector * 10 end script.Parent.Velocity = script.Parent.Velocity + script.Parent.CFrame.LookVector * 5 else script.Parent.RotVelocity = Vector3.new(0,0,0) end script.Parent:SetNetworkOwner(game.Players:GetPlayerFromCharacter(script.Parent.Occupant)) end end
while true do wait() if script.Parent.Occupant then local camera = game.Workspace.CurrentCamera local humanoid = script.Parent.Occupant -- fill this in with your valid humanoid script.Parent.Velocity = script.Parent.Velocity + script.Parent.CFrame.LookVector * 5 * humanoid.MoveDirection:Dot(script.Parent.CFrame.LookVector) script.Parent.RotVelocity = script.Parent.CFrame.UpVector * -5 * humanoid.MoveDirection:Dot(script.Parent.CFrame.RightVector) script.Parent:SetNetworkOwner(game.Players:GetPlayerFromCharacter(script.Parent.Occupant)) end end