2D Player Movement In Unity

preview_player
Показать описание
Learn how to move and jump in Unity!

*SOCIAL*

*SUPPORT*

*MUSIC*
By the Fireplace by TrackTribe

Home for the Holidays by TrackTribe
Рекомендации по теме
Комментарии
Автор

as a complete beginner. I did not understand this video very well but after a few weeks of messing around in unity and i can finally understand what is in this video

fluffystuff
Автор

If anyone's wondering why they can't jump, the "jump" key is set to space by default. To change it to something else, here's the code.
if && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}

if && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}

FireGloves
Автор

If your character is moving left and right but doesn't jump after finishing tutorial you might have missed the point where he moves Ground Check object early in the video closer to players feet and ground. 🎉

deilruchi
Автор

bippity boopity your code is now my property

mitchelllockyer
Автор

Fun Fact, if u look at some of the areas on the script window you will notice that the language is in german

ErraticPulse
Автор

This tutorial was very helpful by showing the whole process of making the script that made the character move, Thank you!

guyinaraincoat
Автор

This is probably the best programming tutorial I've ever seen. Extremely easy and to the point. And for someone who's done this multiple times in the past, but simply don't want to type it all out again, linking the source code makes everything so much easier.

The_Gronne
Автор

The video would be a lot better if you'd actually explain WHY you do certain things instead of just telling us THAT you're doing it. Could have just provided the source code without a video at this point (for the most parts).

leonzuendel
Автор

God tier tutorial, finally something that is short and works great instead of an 18 min video that bugs out!

schauerv
Автор

Very nice video, easy to follow! I just feel like you go over some stuff without explanation, which can make it difficult to understand why we do what we do, like Collision Detection, Sleeping mode and interpolate. I have no idea what it means, but I just do as you say and it works :) Great video overall tho! Big props!

monkeypwners
Автор

This is the only tutorial where I get good physics for the player, thanks so much :)

GD-Monkey
Автор

Here is the script for those who need it


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

public class PlayerMovement : MonoBehaviour
{
private float horizontal;
private float speed = 0f;
private float jumpingPower = 16f;
private bool isFacingRight = true;

[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontal =

if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}

if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
Flip();
}

private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}

private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}

private void Flip()
{
if ((isFacingRight && horizontal < 0f) || (!isFacingRight && horizontal > 0f))
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
}

Arrzee.
Автор

Thanks for the awesome 2D movement in Unity tutorial! Super helpful! 👍

enderpigerdragon
Автор

For everyone that struggles with the player falling through the ground,
Make sure that your ground is not imported from a file but made in the 'Hierarchy'. (if its not imported its grey in the hierarchy otherwise its blue)
Good luck!

its_a_gamer
Автор

I want my cube when the cube is jumping while moving to the right, the cube will jump and rotate 90 degrees to the right as well and there should be a kind of animation and not just instantly changed to 90 degrees.

Edit: just like in Geometry Dash

ThisIsStoneGD
Автор

Amazing, I was able to figure it out from the video with only like 2 errors that were extremely easy to solve. Superb video!

Now I just gotta figure out how to make magic fist attacks with effects, determine a combo system, and design and figure out how to link side profiles to the player sprite with walking animations.

Skylar.H
Автор

that ground checking system is simplistic brilliance, I was stuck for hours trying to think of that and in this moment i am hoping that you're a wizard and it's not just some super simplistic thing everyone has been doing for ages except me

lemason
Автор

This is an amazing tutorial! Thank you so much, I really loved this!

historyjunior
Автор

Thank you for making a tutorial I could follow!

luccabobucca
Автор

Hippity Hoppity Your Code Is Now My Property - "Apleker"

Apleker