Making characters move with wasd relative to world and not to camera

So normally player character moves relative to the orientation and position of the camera. However for my orthogonal game I want to make it easy for the players to move diagonally across the screen with only one key press. How would I do this?

Use a custom movement script like the one @ThanksRoBama made here.

Specifically instead of making the movement directions in world space of the camera. Swap it the axis you want to set it to.

--change the camera CFrame to the CFrame with the axis you want like CFrame.new
local function getWalkDirectionWorldSpace()
	local walkDir = camera.CFrame:VectorToWorldSpace( getWalkDirectionCameraSpace() )
	walkDir *= Vector3.new(1, 0, 1) --Set Y axis to 0

	if walkDir.Magnitude > 0 then --(0, 0, 0).Unit = NaN, do not want
		walkDir = walkDir.Unit --Normalize, because we (probably) changed an Axis so it's no longer a unit vector
	end

	return walkDir
end
3 Likes