Simple First Person Movement in Unity Using C# (Unity Tutorial 2021)

Simple First Person Movement in Unity Using C# (Unity Tutorial 2021)

Channel:
Subscribers:
7,830
Published on ● Video Link: https://www.youtube.com/watch?v=365QHZaIq-w



Category:
Tutorial
Duration: 9:24
30,588 views
732


In this Unity Tutorial, I show you guys how to make a simple first-person movement and rotation script using C#, as well as how to set everything up beforehand.

*An important thing to remember is that you make sure the indenting and formatting of the code is correct, just copying and pasting it from the description might not give you intended results, so you'll need to indent it yourself. Each indentation is 4 spacebar presses. You can look at how the code looks in the video and copy the formatting like that if you like.*

Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movement : MonoBehaviour
{
public Rigidbody player;
public float m_speed, rotatespeed;

void FixedUpdate(){
if(Input.GetKey(KeyCode.W)){
player.velocity = transform.forward * m_speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.S)){
player.velocity = -transform.forward * m_speed * Time.deltaTime;
}
}
void Update(){
if(Input.GetKey(KeyCode.A)){
transform.Rotate(0, -rotatespeed * Time.deltaTime, 0);
}
if(Input.GetKey(KeyCode.D)){
transform.Rotate(0, rotatespeed * Time.deltaTime, 0);
}
}
}

Follow me on Twitter:
https://twitter.com/omogonix

Forgehub:
https://www.forgehub.com/members/omogonix.87700/

Subscribe to my Second Channel:
https://www.youtube.com/channel/UCkylkvUtpvbHfafGfIdMLBQ/featured

Join my Discord:
https://discord.gg/a88vmGD

Facebook Page:
https://www.facebook.com/Omogonix/

Follow me on Instagram:
https://www.instagram.com/uwugonixhalo/

Itch.io:
https://omogonixlachlan.itch.io

Music Used:
Electro-Light - Symbolism (NCS):
https://www.youtube.com/watch?v=__CRWE-L45k&ab







Tags:
unity
unity 2020
unity 2021
unity tutorials
how to make a game
how to make game
first-person movement
fps in unity
first-person in unity
first-person movement in unity
c#
chsarp
programming
how to use c#
c# tutorial
simple
easy
tutorial
omogonix
how to
gaming
game development
game design
coding
scripting