How to Create Player Movement in UNITY (Rigidbody & Character Controller)

preview_player
Показать описание
In this video, I teach you how to make basic player movement in Unity using
the Rigidbody component and the character controller component.

-= Music =-

*****************************************
Music: Dopamine
Artist : DZGRIMX
*****************************************

#UnityTutorials #Unity3D

-= Chapters =-

0:00 Intro
0:46 Rigidbody Movement
12:28 Character Controller Movement
21:41 Outro
Рекомендации по теме
Комментарии
Автор

Join my discord if you have any questions/inquiries

Rytech_Dev
Автор

I really enjoyed this tutorial, but there is a few bugs, one being the the player can look behind themself, I just added this line of code right below the first line of your MovePlayerCamera void,
xRot = Mathf.Clamp(xRot, -90f, 90f);


I also added where the player does not see the Cursor while playing, put this right below your floats:


void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

But overall great tutorial Ive been practicing unity for a few weeks now these are just some tips to make this script better.

Yayboo
Автор

Life saver video!

To anyone struggling with the Character Controller component's isGrounded flickering between true and false.
Use the rigidbody technique provided at 11:10 to create a check. 'Physics.CheckSphere(PlayerFeet.position, 0.1f, FloorMask);'

Edit - I found that the player object would get stuck in the floor and would have to jump a couple times before jumping properly, changing the CheckSphere from 0.1f to 0.0001f fixed the issue.

krane
Автор

Extremely helpful! I was looking forever for a tutorial 3rd person with only rigidbody... Thanks! 😊

stickman
Автор

omg thank you from the bottom of my heart you're a life saver ... I had a problem in my rigidBody movement script and I found the solution while watching your video ... I've been looking for a solution for 2 days now

joubran_
Автор

For anyone who has a problem with moving diagonally doubling movement speed, locate the following line within your MovePlayer() function:
Vector3 MoveVector =
Now replace it with this line:
Vector3 MoveVector = transform.TransformDirection(Vector3.ClampMagnitude(PlayerMovementInput, 1f));
This let's us set the maximum magnitude that PlayerMovementInput can have to equal 1.
Explanation:
PlayerMovementInput the way we've defined it, gets its magnitude value from our input axis. This means that when we press W, the vector would have a value of 1 in the z direction. The problem comes when we press two keys at once, like W and D. Now the vector's value will be 1 in the z direction PLUS 1 in the x direction, doubling our intended value for PlayerMovmentInput and by extension, MoveVector when it is used elsewhere. Vector3.ClampMagnitude(*your Vector3 here*, *your value here*) lets us keep the direction component of the vector, while limiting the magnitude to whatever value we choose, in this case 1.
One alternative solution would be to normalize PlayerMovementInput like so:
Vector3 MoveVector =
What this does is set the magnitude of our Vector3 to 1. That's it. It's either nothing, or 1. This works, but it loses the smoothing effect of the Input.GetAxis we used to get our inputs, making movement jerky and unpleasant. I wouldn't recommend it in this instance.

IAmStickyWicky
Автор

Tqsm dude pretty much like every tutorial shows the tutorial for movement but you are the one of the few awesome channels that show how to create gravity and jumping, Thanks man this video helped alot

absolutestrange
Автор

This channel is so underrated wtf i just found out about it searching for rigid body movement thank you so much very informative video i subbed

styliejoker
Автор

Ive seen a lot of tutorials for rigidbody fps controllers but this is by far the best built and the most well explained tutorial, thank you for making this <3

gulikaontop
Автор

Thank you a lot for this tutorial, a good thing to note is to turn on rotation lock in the rigidbody constraints section. It took me a day to figure this out :(

bryanz
Автор

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RigidbodyMovement : MonoBehaviour
{

private Vector3 PlayerMovementInput;
private Vector2 PlayerMouseInput;
private float xRot;

[SerializeField] private LayerMask FloorMask;
[SerializeField] private Transform FeetTransform;
[SerializeField] private Rigidbody PlayerBody;
[SerializeField] private Transform PlayerCamera;
[Space]
[SerializeField] private float Speed;
[SerializeField] private float Sensitivity;
[SerializeField] private float JumpForce;

void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}



// Update is called once per frame
void Update()
{
PlayerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
PlayerMouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

MovePlayer();
MovePlayerCamera();

}

private void MovePlayer()
{
Vector3 MoveVector = * Speed;
PlayerBody.velocity = new Vector3(MoveVector.x, PlayerBody.velocity.y, MoveVector.z);

if
{
if (Physics.CheckSphere(FeetTransform.position, 0.1f, FloorMask))
{
* JumpForce, ForceMode.Impulse);
}
}

}

private void MovePlayerCamera ()
{
xRot -= PlayerMouseInput.y * Sensitivity;
xRot = Mathf.Clamp(xRot, -90f, 90f);


transform.Rotate(0f, PlayerMouseInput.x * Sensitivity, 0f);
= Quaternion.Euler(xRot, 0f, 0f);
}
}

excaliber_bruh
Автор

I exactly looking for this since a Day, But at last i found you so this made my Day : )

AryanSingh-usej
Автор

edit: Never mind i figured out the prob So just left to say great work!!

MrSmoofist
Автор

20:36 Gravity 🤣🤣🤣

Thank You for teaching Rigidbody and Character Controller in an easy to understand way

happy new Year~

Studio-Rok
Автор

Tysm lol, been redoing the movement for a project since the old one had way too many weird bugs

micrwav_able
Автор

Best tutorial I've seen! Helped me a lot!

SnowyRedstone
Автор

There is a saying going like:
"The louder you type, the better coder you become"

patek
Автор

Thanks a lot ! I ve been searching for an updated movement script for 2021 and i ve finally got it . It works, I'm so grateful for this tutorial and for your work. You just got a new subscriber!

lifelike
Автор

Thsnks for video i needed the help!!!! 🙌🏾

Ksungaa
Автор

I have had some problems whit the rigidbody controller so thanks grate vid!!

odinfrodin