(New) Unity 2D Top down Movement in 1 MINUTE

preview_player
Показать описание
A very simple way to move a 2D top down character in Unity

• Unity version in the video: 2020.3.40f1

#unity #gamedev #unity3d #unity2d #2d #gaming #indiegame #indie
Рекомендации по теме
Комментарии
Автор

44 seconds and my movements working how tf aren't you famous

chasemclean
Автор

This is EXACTLY the kind of tutorials I've been wanting to see. Kudos to you!

xfermi
Автор

❤️ omg. After 4 hours into making my first game and watching countless tutorials I finally had control of my capsule. Thank you!

Hamlet
Автор

The code isn't working so here it is :)

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

public class PlayerCtrl : MonoBehaviour
{


public float movSpeed;
float speedX, speedY;
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
speedX = * movSpeed;
speedY = Input.GetAxisRaw("Vertical") * movSpeed;
rb.velocity = new Vector2(speedX, speedY);
}
}

AymanIscracked
Автор

cant believe how easy and short that was, thank you

joebeerlobe
Автор

If you notice your character is moving faster diagonally, you have to normalize the vector. If you're pressing both W and D keys for example, your character will have a magnitude of 1 on each axis, and your movement speed will actually get multiplied by 1.41 (or radical of 2).

A very simple fix to this is at the end
where it says
rb.velocity = new Vector2(speedX, speedY) to turn it into rb.velocity = new Vector2(speedX, speedY).normalized();

Hope this helps!

ionpopescu
Автор

There's one flaw I noticed, the player moves faster on the diagonals, so I just put speedX and Y in a Vector and normalized them:

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

public class PlayerController : MonoBehaviour
{
public float movSpeed;
Vector2 velocity;
Rigidbody2D rb;

void Start()
{
rb = GetComponent<Rigidbody2D>();
}

void Update()
{
velocity = new Vector2(Input.GetAxisRaw("Horizontal"),
velocity.Normalize();
rb.velocity = velocity * movSpeed;
}
}

LiittleSoul
Автор

would probably be better to use a vec2 instead of x and y so you can easily normalize it, otherwise keyboard players get to go much faster diagonally

justalonelypoteto
Автор

Kudos for making the exact tutorial with no unnecesary bits or anything, thank you so much!

cindyespindola
Автор

This is literally the best thing ever, I dont need to waste 20 minutes finding the code, this is explained amazingly and a link to copy it, dude is a legend

comsorado
Автор

45 second tutorial and its the first that actually worked for me you the realest 🙏

Uhhok
Автор

It would probably be better to define movement as its own Vector2, that way you can normalize it and multiply it by the movSpeed variable, otherwise you will be going twice as fast when you move diagonally.

averageunitydev
Автор

Right to the point and it makes sense. Thank you so much for this. Other videos had me struggling

connorshaw
Автор

Broooo! you're the best! You literally in 44 sec explain something that other youtubers explain in 5-6 mins! Respect!

Sqadleader
Автор

Liked, subbed, and shared to a few people. Ty King.

Euclivid
Автор

Dude, thank you so much, absolutely flawless!

ljjmass
Автор

OH MY GOODNESS IT HAS BEEN THAT EASY ALLL THESE YEARS!!! WHY DID EVERYONE MAKE VIDEOS TAKING 45 MINUTES FOR THIS?!

ColeR-msqy
Автор

in unity 6 velocity is now linearVelocity

yirayder
Автор

Dude!!!! PLEASE make more Unity videos like this!
Show me how to make a 2D background!
Show me how to add interactables like coins or enemies.

JackBurrows-cg
Автор

i followed exactly and theres no movSpeed under the script

_LuckyyYT