So I've been working on my 2d side scroller for a few days now and I have a lot done, but I'm testing things that need fixing and if I run at an angled obstacle my character moves slowly around it, like when he's running into the objects slanted side he's moving in a slant, is there a way to fix the script to where He stays walking one way PERMANENTLY even if there's a slanted object? Like a way to keep him in a straight line no matter what happens?
-- Declare varaibles
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local moveVector = Vector3.new(0,0,0)
-- Handle inputBegan event (when player first presses a key)
userInputService.InputBegan:connect(function(inputObject)
if player.Character then
if inputObject.KeyCode == Enum.KeyCode.A then
moveVector = moveVector + Vector3.new(-1,0,0)
end
if inputObject.KeyCode == Enum.KeyCode.D then
moveVector = moveVector + Vector3.new(1,0,0)
end
if inputObject.KeyCode == Enum.KeyCode.Space then
player.Character.Humanoid.Jump = true
end
end
end)
-- Handle inputEnded event (when player releases a key)
userInputService.InputEnded:connect(function(inputObject)
if player.Character then
if inputObject.KeyCode == Enum.KeyCode.A then
moveVector = moveVector + Vector3.new(1,0,0)
end
if inputObject.KeyCode == Enum.KeyCode.D then
moveVector = moveVector + Vector3.new(-1,0,0)
end
end
end)
-- On renderstepped update the character's motion based on what keys
-- are currently being pressed
runService.RenderStepped:connect(function()
if player.Character then
player.Character.Humanoid:Move(moveVector)
end
end)
