I need help with Character moving system

What do I want to accomplish?ONLY HELP IF YOU’VE GOT TIME!!
I want to make, so when a player Presses W, A, S or D the Character moves up, to the right, down or to the left, BUT, u do NOT need to hold the button, so if I press W once, it will continue walking up.

But i want the character to move, in the white lines, so they cant walk outside of it.


And can only change Direction if its in a radius of the corner.

I don’t know how to make the character to continue moving after just pressing the button or how to make so it can go outside of the lines. Neither do I know how to make it so its only able to turn while close to the corner!

I’ve been watching tutorials, looking through functions in studio, and Dev Hub but can’t find anything!
So that’s also why I Haven’t wrote the whole script here on devForum, I deleted the rest since it didn’t work!

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")


UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.W then
		print("The key: W, was pressed! By the player, " .. plr.Name)
	end
end)

UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.A then
		print("The key: A, was pressed! By the player, " .. plr.Name)
	end
end)

UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.S then
		print("The key: S, was pressed! By the player, " .. plr.Name)
	end
end)

UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.D then
		print("The key: D, was pressed! By the player, " .. plr.Name)
	end
end)

Only help if you got time, I’m not here to waste anyones time!

1 Like

Here is some APIs that can be used to do various things you asked about:

  • Moving the player’s character manually (so they continue to walk) can be done with Humanoid | Roblox Creator Documentation (might need to disable default player controls script)

  • Finding the distance between 2 points (to check if they are close to a corner, wall, etc) is done like this:

local v1 = workspace.Part1.Position
local v2 = workspace.Part2.Position
local distance = (v1 - v2).Magnitude

To have it so when they press a key and basically remembers what they pressed and continues going that way until they press another, you should probably keep track of the “last pressed key” and can do some movement based on that, as well. Only set it if it’s WASD.

To achieve something where the player only walks along the lines in your picture, you can round the goal position they are walking to with MoveTo to be aligned with whatever the grid is (for example, round to nearest stud). This would prevent them targeting a point between the lines.

Hope this helps in some way.

3 Likes

I’m pretty new to scripting so I don’t understand advanced stuff and for me that’s advanced. Imma try my best, thanks for the help!

By the way, if this helps you maybe understand a bit more, It’s gonna be a Snake game like the original “Snake”! :slight_smile: