Grid Movement Help

hi…

So I want to try making a game I think it’s called ‘roguelike rpg’ I’m not sure… So I made this:

I already get the player to spawn as the cube when the player added. The cube is called ‘Base’. I want to use it to control the movement in the server and will render the character model in the client. The cube (player’s character) doesn’t have a humanoid because I want to customize the health and movement system.
image

Now I want to make the character move when the player pressed the WASD keys. But… How? I already have a local script that will fire a RemoteEvent to the server when the keys are pressed but how do I move the character in the server? I just need to know what I gotta use and do. I have no idea where to start. The first idea I had in mind is to have nodes around the map:


But still… I don’t know where to start. So… I’d like to hear what y’all think I can di I aprpeciate any kind of help.

Thanks : )

1 Like

I would recommend using Humanoid.MoveDirection. You can ignore the y component if players aren’t climbing, just use the X and Z components. Not too sure what the best way to do this would be, but I would just see which one has a greater absolute value and use the sign of it:

local function roundToAxes(inputVector)
  local x = inputVector.X
  local z = inputVector.Z
  if math.abs(x) > math.abs(z) then
    return Vector3.xAxis*math.sign(x)
  else
    return Vector3.zAxis*math.sign(z)
  end
end

You can then multiply that resulting unit vector by the side/grid length and add that on to the cube’s position. I don’t know how exactly you want to do movement, if it’s a hold situation with a delay or what. You could use UIS.InputBegan() to detect individual key presses(if that is the system you are going for), and then use the Camera.CFrame.LookVector. You could rotate it based on the key pressed. Hope this helps!

You can detect the WASD keys being pressed with something like:

-- LocalScript inside StarterPlayerScripts
local ContextActionService = game:GetService("ContextActionService")

local function wPressed(actionName, inputState, inputObject)
	if actionName == "WPressed" then
		-- The key was pressed down. You can use ~= Enum.UserInputState.Begin to detect when it's released.
		if inputState == Enum.UserInputState.Begin then
			-- TODO: Send the server a "move forward request" through a remote event
		end
	end
end

ContextActionService:BindAction("WPressed", wPressed, false, Enum.KeyCode.W)

-- TODO: Do similar things for A, S, and D

With the code above you can have the client detect wasd input. If you want the actions to be server sided, you can then send the input to the server through a remote event. Then on the server side, wait for OnServerEvent and when that event fires, move the player in the specified direction.

1 Like

i made the player character Humanoid-less

Then I’d recommend merging my function with the code BendsSpace provided to detect and handle key presses. You would probably want to have my code run client side to get the final vector to send to the server. On the server you can have a delay per player. I would also recommend using the unit of the vector the client sends and multiplying it by the grid length so players don’t step too far.