Character Controller in Unity 2D! (Move, Dodge, Dash)

Character Controller in Unity 2D! (Move, Dodge, Dash)

Code Monkey

4 года назад

117,734 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Cash-Trax24
@Cash-Trax24 - 13.09.2023 06:31

Insane tutorial. Little fast sometimes, but better than being obnoxiously slow. Thanks for all the help!

Ответить
@shwetagarg4798
@shwetagarg4798 - 14.04.2023 13:50

I want to delay my dash instead of players smashing dash button.

Ответить
@shwetagarg4798
@shwetagarg4798 - 09.04.2023 18:10

you forget to tell, how camera is following the player

Ответить
@ksong5589
@ksong5589 - 15.02.2023 16:25

awesome bro

Ответить
@darkpyroftwreal9610
@darkpyroftwreal9610 - 14.01.2023 09:21

How can I add a cooldown to this?

Ответить
@rnkgx1437
@rnkgx1437 - 11.12.2022 02:19

hey how i can add a cooldown for dash because ican spam dash every time

Ответить
@Sheplord
@Sheplord - 08.10.2022 03:34

hey, i couldn't get the movement part of the tutorial to work so i followed another tutorial. Then I came back and tried to impliment the dash but although i got no errors, the dash wouldn't work. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb2d;
private Vector2 moveInput;
private bool isDashButtonPressed;
private Vector3 moveDir;


// Update is called once per frame
void Update()
{
moveInput.x = Input.GetAxisRaw("Horizontal");
moveInput.y = Input.GetAxisRaw("Vertical");

moveInput.Normalize();

rb2d.velocity = moveInput * moveSpeed;
if(Input.GetKeyDown(KeyCode.Space))
{
isDashButtonPressed =true;

}
}
private void FixedUpdate()
{
if(isDashButtonPressed){
float dashAmount = 50f;
rb2d.MovePosition(transform.position + moveDir*dashAmount);
isDashButtonPressed = false;
}
}
}

Ответить
@MuradMohdZain
@MuradMohdZain - 05.10.2022 04:26

Downloaded the assets and import into my unity new 2D project. The character become pink color and tilemap not showing. Please help. I'm using unity version 2022.1.18f1

Ответить
@MuradMohdZain
@MuradMohdZain - 04.10.2022 19:59

Amazing tutorial. Loved it!

Ответить
@bugsephbunnin4576
@bugsephbunnin4576 - 14.07.2022 07:51

Hi! I have a question.
How do you use Vector3 while there are only two parameters?
Also, is there any difference between using Vector2 and Vector3 since you are using only the parameters x and y?

Ответить
@letsgamingde420
@letsgamingde420 - 26.06.2022 15:48

Did everything just like in the Video (except for the animation part, but that doesnt really matter) but somehow my player wont das down. He does dash in all other directions but when i move down and dash, it only looks like he would dash, but he doesnt really get transported (I checked with Logs)
Anyone knows why and how to fix?

Update: It was colliding with the player and so it did only move to the hitbox of the player (dont know why that only happened while moving down tho)
In the if-statement for the raycastHit2D im now also checking if its not the player

Ответить
@mikem8518
@mikem8518 - 20.06.2022 07:58

I know that this is an older video but I cannot get the dash to work. I have been through the video multiple times and I see the debug triggers that fire when it goes into the dash. Even the most basic one at the beginning (code) didn't work let alone the more complicated one. I feel that there is something wrong with the MovePosition. And yet i get no errors

Ответить
@SGUDevs
@SGUDevs - 12.04.2022 00:24

wb 3d character?

Ответить
@emanueltejadacoste2250
@emanueltejadacoste2250 - 22.02.2022 04:52

I joined your discord and im wondering if it was hacked or something xd Im lost

Ответить
@neozoid7009
@neozoid7009 - 11.02.2022 10:45

why did you make the move speed as a constant ??

Ответить
@neozoid7009
@neozoid7009 - 11.02.2022 09:21

Super Cool .Awesome Tutorial , Really appreciate . Keep making cool and awesome tutorials

Ответить
@VikalHimanshu
@VikalHimanshu - 04.02.2022 21:15

I was finally able to make dash work. Now it goes through enemies but not walls. But there is one issue. If I run into an enemy and try to dash in the enemy's direction the player doesn't dash. How can I fix that?

Ответить
@TimmyJTech
@TimmyJTech - 26.01.2022 10:14

Hello! Love this tutorial thanks so much! Was just wondering how to change the sprite to be something else. I added in my own sprite over top of your sprite sheet then made it into a material but it is somewhat blurry because its in 256 not 512. i need to downscale it somehow? Also how would I add in different arms/legs for left/right? Thanks for your time!

Ответить
@umerfarooqchattha5685
@umerfarooqchattha5685 - 26.01.2022 07:22

bullshit bakwas

Ответить
@atahakantan8498
@atahakantan8498 - 14.01.2022 15:30

Bad - I can't seem to make heads or tails of the downloaded scene from the directory given in the description. The character does not load and the meshes aren't located in the project files (at least not from what I can see.) As well as when I try to load the game without doing anything else, I get a huge amount of compile errors.

Ответить
@trystanlyons3110
@trystanlyons3110 - 28.11.2021 11:11

Thanks for the tutorial but when I start the game it automatically sets isDashButtonDown to true how do I fix this

Ответить
@Luca-ux3op
@Luca-ux3op - 13.10.2021 22:34

Thanks! Finally a good and uncomplicated dashing tutorial :)

Ответить
@atamanatm1361
@atamanatm1361 - 12.10.2021 23:12

THANK YOU VERY MUCH

Ответить
@zetanhwang4589
@zetanhwang4589 - 26.08.2021 20:48

I write like this:
var hit = Physics2D.Raycast(transform.position, direction, moveSpeed, raycastLayer);
if (hit.collider)
{
//do something
}



It hit nothing, but if I remove the layer param, it hit the player easily, why? I'm got crazy to handle this issue after goole all the night :(

Ответить
@grayzone8882
@grayzone8882 - 22.08.2021 12:26

How do I make a player game object?

Ответить
@adamantium6400
@adamantium6400 - 17.08.2021 17:17

The bit that I need most is the dash animation bit, and you glossed over it like it was the easiest thing in the world haha I have checked your mesh video that I see you have recommended to others but that went completely over my head. Have you covered the dash effect in any other videos? Thanks

Ответить
@tsukinoakuma7603
@tsukinoakuma7603 - 22.07.2021 11:52

That feeling with the coder uses the correct brace style

Ответить
@Branzoaica
@Branzoaica - 16.07.2021 18:05

i did exactly as you did and it doesn't work idk i think that my VS code is bugged cuz i can't even autocmplete stuff idk why

Ответить
@Branzoaica
@Branzoaica - 16.07.2021 17:27

for some reason this code private bool isDashButtonDown; gives me this error error CS1519: Invalid token ';' in class, struct, or interface member declaration why???

Ответить
@davidregalado3037
@davidregalado3037 - 29.06.2021 22:03

I want it to be impossible to move diagonally how do I make that?

Ответить
@iamacat9400
@iamacat9400 - 12.06.2021 23:13

me after watching the video: i see it looks simple enough

me after watching the video: i have 69 errors and my laptop is on fire

Ответить
@davidpak271
@davidpak271 - 11.06.2021 07:15

Hi, I can't find a video of Input System on your channel, is it because you don't recommend using it? If you do, would you be able to create one please? Thanks

Ответить
@andsegcar
@andsegcar - 21.05.2021 15:37

Great video, just a quick question.
Why did you use "* Time.deltaTime" while calculating the roll speed and did not use in any other movement calculation?

Ответить
@mofodumbas
@mofodumbas - 04.05.2021 01:47

I found that Physics2D.queriesStartInColliders comes quite handy to handle raycast start collision ;)
Awesome tutorials, I'm learning a lot from your videos!

Ответить
@Raybro16
@Raybro16 - 04.04.2021 01:37

I've been stuck trying to implement a dodge roll in my game project all week, I'm so glad to have found this video!
Now i have to find a way to format it into my code sonit works with double tapping ;w;

Ответить
@echo9dev
@echo9dev - 29.03.2021 21:04

Please make on tutorial on lighting, that the only reason I’m here

Ответить
@iR3dy
@iR3dy - 07.03.2021 01:22

Me again, Why would my player be sliding with a rigidbody I have gravity set to 0 and i have zed froze??

public void FixedUpdate()
{
Move();
}
public void Move()
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
input = input.normalized;

animator.SetFloat("Speed", input.magnitude);

bool isIdle = input.x == 0 && input.y == 0;
if (isIdle)
{
animator.SetFloat("LastInputX", lastInput.x);
animator.SetFloat("LastInputY", lastInput.y);
}
else
{
playerRigidbody.velocity = input * walk;
animator.SetFloat("Horizontal", input.x);
animator.SetFloat("Vertical", input.y);
lastInput = input;
}


I use to use playerRigidbody.MovePosition(transform.position + input * walk * Time.deltaTime);
and I didnt have an issue but like you said doing so cause a buggfy effect when going against something it cannot pass through

Ответить
@ghostpotato1322
@ghostpotato1322 - 30.01.2021 08:04

Is it possible to do the dash animation and stuff as a dodge

Ответить
@zwartz
@zwartz - 15.01.2021 16:48

Okay, I know I'm a year late, but I really want to put a cooldown on the roll ability, but since I'm new to C# and state machines especially, I can't figure it out for the life of me!

Ответить
@SwampySongs
@SwampySongs - 12.01.2021 00:15

With this, how would you handle when the player is affected by other physics systems such as knockback?

Ответить
@polar5153
@polar5153 - 12.12.2020 09:52

how do you make the character go slower cause i did it and it went way to fast for my liking so if someone could help me it would be very much obliged.

Ответить
@anupthakurwar7693
@anupthakurwar7693 - 02.12.2020 15:21

Its awesome 😊 but 🤔
I want to move my player in x & y direction like it moves on horizontal 3d road. Can you help me out?

Ответить
@anupthakurwar7693
@anupthakurwar7693 - 06.11.2020 16:03

Please show the code of character_base.

Ответить
@mu4fin582
@mu4fin582 - 25.10.2020 14:41

Question When I Downloaded Utils and "DashEffect" code i have this error

(Dash Effect):
"The Name GameAssets does not exist in the current context"

Ответить
@randomgamer3964
@randomgamer3964 - 21.10.2020 17:38

My character goes super fast whenever i move, everything is fine, but could someone help me with slowing down my player thanks

Ответить