Best way of moving player

Hi. I’m making some sort of Minecraft clone (i know… i know…) and I have question about player movement. Every method I used has the same problem. If i fall down and stick into wall my player is glitching or even stopping.

What is the best way to control the player and avoid these problems? I could disable moving if player is not touching ground but I want some control in air and it is important because if i jump i want to move in air to the next block.

Well, there is really no best way to control a character on screen. It all depends on what kind of game you’re making.

Since you’re making a Minecraft clone, I don’t think realism or physics-based movement matters that much, so I’d recommend a simple First Person Character Controller.

Attach a character controller to your player, and then create a C-Sharp script called FPSController.

Just paste my code into it and the rest is pretty straightforward.

using UnityEngine;

public class FPSController : MonoBehaviour {
	public CharacterController characterController;
	public Camera cam;
	public float XSensitivity, YSensitivity;
	public bool invertPitch, clamp;
	public int minY, maxY;
	public bool grounded, jumping;
	public float forwardSpeed, horizontalSpeed, jumpPower, gravity;
	[HideInInspector] public float jumpSpeed, verticalRotation;
	void Update() {
		float mouseX = Input.GetAxis("Mouse X"), mouseY = Input.GetAxis("Mouse Y");
		if (!invertPitch)
			mouseY = -mouseY;
		verticalRotation += mouseY * YSensitivity;
		if (clamp)
			verticalRotation = Mathf.Clamp(verticalRotation, minY, maxY);
		transform.Rotate(0, mouseX * XSensitivity, 0);
		cam.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
		if (Input.GetMouseButtonDown(0))
			Cursor.lockState = CursorLockMode.Locked;
		float horizontal = Input.GetAxis("Horizontal"), forward = Input.GetAxis("Vertical");
		grounded = characterController.isGrounded;
		if (grounded) {
			jumping = false;
			jumpSpeed = 0;
			jumpSpeed -= (gravity * 25) * Time.deltaTime;
		if (Input.GetAxisRaw("Jump") != 0 && !jumping) {
			jumping = true;
			jumpSpeed = jumpPower;
		Vector3 motion = new Vector3(horizontal * horizontalSpeed, jumpSpeed, forward * forwardSpeed);
		characterController.Move((transform.rotation * motion) * Time.deltaTime);

Let me know how this works for you, and if you have any problems!

I’d recommend using unity’s First Person Character Controller (which can be found in the ‘characters’ folder when you go to the import assets tab in the editor) with a sphere collider around the camera. It’s simple but should fix all the issues you’re having.

I used this method to have smooth movement in my game: