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)

8 comments

0
0

Yes, but the other was posted 11 hours ago, so I didn't think anyone would've seen it

0

Is there even anything wrong with this script?

0

Well, the script works fine, it's a problem that needs solving, if I run at an object I seem to slowly walks to the side until I'm walking around the object and out of the sidescroller line of obstacles

0

By the way thanks for the help, I started scripting about a week ago and you in particular have helped alot, great to see you're so active in helping people here

0

I have no life /:

0

nah fam, xD you're learning this kind of stuff, and that's something the average guy can't say.

0

https://www.roblox.com/item.aspx?id=405394849 there's a link, run at the the box and you'll see the player move around it