Finally someone who acknowledges the importance of why. So many videos that I have watched just instruct you WHAT to type in to the code and which checkmarks you should have but never do they tell you WHY, which makes the information totally useless because you can never use it in any other situation.
This is exactly what made me give up on game development before. You can watch a tutorial and implement everything correctly but if the video doesn't explain, you still don't understand anything
This, by far, actually taught me something. Thank you so much for making this video, Dani. At the very least, I think I've learned some core concepts of the codes you have introduced here.
Im just seeing this now after using many other vids that didn't explain as well as yours. I have decided to make a game on spring break, thanks a ton and i'm sure i'll watch more of the vids you have made to help me
This is the first video of yours I've watched, and the best tutorial I've seen that (as many others have pointed out) actually explains WHY you're writing a certain line of code and how everything interacts with each other as opposed to just telling you what to write. I ended up taking notes on paper and also adding notes into the script so I can go back and remember what the fields and everything are actually doing. Thanks SO much for this, subscribing and probably devouring all the rest of your videos!
This is the first player movement script that REALLY worked for me, that I understood. I'm relearning Unity after I took a huge break from coding so thank you so much for helping me bounce back
you're a life safer. Most tutorials dont explain what we're coding and when i did something wrong i wouldnt know how to fix it. But you explained very well. thx
best tutorial ive seen on programming for beginners!! like any new subject youre completely unfamiliar with, there's a whole universe of things you need to learn in order to make your own mental image and understanding of the topic in order to really learn stuff instead of memorizing. the way its explained on this video really helps with that
This is one of the best videos i've seen for learning this! You really go into detail about what things mean and when you should use them. Thanks alot! I'll definitely recommend this video to anyone i know who wants to get into coding :))
Every time I typed Rigidbody2D in my code it didn't call it, and I have no clue how to fix this. Did something change in the 2022 version or am I making a mistake? I saw your comment was from only one month ago so I was wondering if something similar happened to you.
I have an error (Assets\Scripts\BirdGoFly.cs(7,13): error CS0246: The type or namespace name 'RigidBody2D' could not be found (are you missing a using directive or an assembly reference?)) and I'm confused on how to solve it, do you have any suggestions?
When I go to write the code in C# it doesn't show me an option to connect to Unity. Alongside that it tells me that it is in 'Miscellaneous Files' rather than 'Assembly-CSharp. And when I go to call on RigidBody2D like you do at 18:15 it doesn't connect to anything. Would you know the reason? I also wanted to say thank you for taking the time to make this wonderful video.
Hey, I'm new to game development so your tutorial is super helpful but I have trouble implementing what you've shown. I think I have copied everything but I can only move to the right but not to the left why could this be?
I need help with something for my own game, The code itself works fine. But the inputs moveSpeed and jumpForce are way to high for my character, is like if he was sonic. I tried changing them to a lower value, like moveSpeed to a 1f and the jumpForce to a 5f but when I did it. The player moved but only for a little bit, after a certain amount of time it would just freeze and I could only go the opposite way of the freeze, also. The jumping, after I changed the values, Did not work! Please Help me! thank you for the rest of the tutorial but I need lots of helps!
First, thanks for the tutorial! But I'm having issues with moving the character still. I don't know where I've gone wrong. For some reason I can move the character by keyboard input BUT the character keeps moving without stopping even though I'm no longer clicking on the keyboard. Do you have any ideas why? I have the exact same script so I'm not sure if it's a setting else where that I have wrong.
I'm having trouble with my player being able to jump in the air. if it helps diagnose, my OnTriggerExit2d is not being used is what unity says. Code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { private Rigidbody2D rb2D; private float movespeed; private float jumpforce; private bool isjumping; private float moveHorizontal; private float moveVertical; // Start is called before the first frame update void Start() { rb2D = gameObject.GetComponent(); movespeed = 4f; jumpforce = 23f; isjumping = false; } // Update is called once per frame void Update() { moveHorizontal = Input.GetAxisRaw("Horizontal"); moveVertical = Input.GetAxisRaw("Vertical"); } void FixedUpdate() { if(moveHorizontal > 0.1f || moveHorizontal < -0.1f) { rb2D.AddForce(new Vector2(moveHorizontal * movespeed, 0f), ForceMode2D.Impulse); } if (!isjumping && moveVertical > 0.1f) { rb2D.AddForce(new Vector2(0f, moveVertical * jumpforce), ForceMode2D.Impulse); } } void OnTriggerEnter2D(Collider2D collision) { if(collision.gameObject.tag == "Platform") { isjumping = false; } void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "Platform") { isjumping = true; } } } }
I am getting intetested in game dev and you are beautifully teaching me the way through it. I thank you so much, I devoured this video in the best sense of the term. It shows the crazy amount of devotion you have to teaching. Thank you once more.
The moving code is not working when I go to unity it shows "The name ForceMode2D doesn't exist in the current context" please tell me how to fix this error I even put the Add Force but it still shows the same error
The error message means that you aren't supposed to be able to use "ForceMode2D" in that location. So the most likely explanation is that you made a typo in that line of code. My guess based on peoples typical mistakes, is that your () aren't correctly setup there. 🙂
So, I know this has probably been asked but, I've followed the tutorial character for character and ensure all of my capitalization and symbols are exactly the same as in the video. However I cannot seem to get away from a "CS0246" error saying that the namespace name RigidBody2D couldn't be found. Can anyone offer any help or advice? Because I have no ideas, since you clearly didn't get this error in the video and I'm following along to the letter.
Na this dude is legit he makes sure to think about what would a new Dev be thinking he does not only think from an experienced point of view subbed man
This is a great tutorial! I've been searching for a way to use addForce to move a character around and this has been really helpful! With regards to the 3 different ways of checking if the character is grounded before it can jump, is there much of a difference between using raycasts, overlaps and layer masks, and the collision detection method that you used? Is one easier to control than the other or does one perform better than the other? Thanks again for the great vid!
The best tuto ever, finally someone I understand and find easy to follow with! Just started out and your video really helped out so much, thank you! cheers
i follow the tutorial from point a to point b but i never get those pop ups that for example say Rigidbody2D and so when I go back into Unity my player doesnt move
hey guys. his Scipt doesnt work for me so i decidet to make it work. i dont know if it work for u too but here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { private Rigidbody2D rb2D; private float movespeed; private float jumpforce; private bool isjumping; private float moveHorizontal; private float moveVertical; // Start is called before the first frame update void Start() { rb2D = gameObject.GetComponent(); movespeed = 1.5f; jumpforce = 10f; isjumping = false; } // Update is called once per frame void Update() { moveHorizontal = Input.GetAxisRaw("Horizontal"); moveVertical = Input.GetAxisRaw("Vertical"); } void FixedUpdate() { if (moveHorizontal > 0.1f || moveHorizontal < -0.1f) { rb2D.AddForce(new Vector2(moveHorizontal * movespeed, 0f), ForceMode2D.Impulse); } if (isjumping && moveVertical > 0.1) { rb2D.AddForce(new Vector2(0f, moveVertical * jumpforce), ForceMode2D.Impulse); } } void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Platform") { isjumping = true; } } void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "Platform") { isjumping = false; } } }
@@GunSpyEnthusiast took me a bit but i fixed it. check the "void FixedUpdate" part and make sure the f in fixed is capital. thats why mine didnt work at least
Good vid but I keep getting this error when I try to use OnTrigger/CollisionEnter "OnTriggerEnter(Collider2D) must declare a body because it is not marked abstract, external, or partial [Assembly-Csharp]
I copied the video exatcly but I have a problem qwq. I can't get the Collider part right. I did everything correct in the code and in unity but it won't work. I also know it definetly has something to do with the last two coding blocks...everything else works. Does anyone have an idea what i could try to fix it qwq.
When I hold down my uo key it just keeps moving up (like flappy bird) I believe I followed the code exactly as shown so why isn't the jump deactivating when it leaves the ground..
I have watched so many tutorials on youtube by now and this is by far the best one! you explain things so thoughtfully and clear. keep it up, you gained a new subscriber!
I put in walls to change my speed freely without falling off, but whenever I touch a wall, I lose the ability to jump, I'm looking at the code and I don't know why
My player seems to accelerate when applied force and slides a bit due to the inertia. Could someone help me move the player at a constant speed and not slide in the end?
Super helpful video! I've been going through this Unity intro series and learning a ton! You are great at anticipating my questions and explaining everything. I watched your pixel art tutorial, and am excited for the C# series too. Thank you so much!! It's hard to believe resources like this are free.
For some reason, adding the player controller C# script, when I add it to the player it says "Cannot add script component "PlayerController" because the script class cannot be found."
I've never been so thankful in my life. I've spent over 20++HRS trying to fix my jumping mechanics going through soo many tutorials hoping it would fix my issue and THANKFULLY this has been the one and only that has fixed my issue. Thank you soooo much!!! I am subscribing and liking this video and keeping this Channel as my go to for my issues. Its so informative especially for a beginner. I can't help myself but to thank you again once more.
why didnt you post the code in the comments or the description. im getting "Top-level statements must precede namespace and type declarations." and to my understanding i copied your working code word for word and i dont know if its diferent because its not posted in an easy to view mannor.
i bypass the issue of a program atuomatically refering to something using the same words as a varible, simply by calling things things like " movementing ", and " slide to the left, slide to the right. "
Do NOT forget to set the ground detection collider as a trigger xD you will take 15 minutes to figure out why your character can still take off like a spaceX rocket LOL
i am unable to add crouching to the code because i don't really understand how to change the speed of movement while crouching, the code works fine i just couldn't find any good tutorials about crouching
"dont get frusterated if you dont understand- " me who obtained a headache that lasted for multiple hours because of how complacated making a sprite is in unity : a little late.
Great content! explains all details one by one. Just want to ask if this is the better approach compared to Rigidbody.Velocity when it comes to responsiveness of the movement. Some says the AddForce method makes the player like "sliding" instead of running compared to the responsiveness of Velocity. Hope you can compare those two. Cheers!
Velocity will make your object instantly move at a certain speed, and is great for top down games where you need full control over the Player movement. Where as AddForce uses physics to "push" a object that is affected by mass and gravity, and is great for platformers where your character is running around, and needs to be influenced by other objects. It really depends on the type of game you are creating, and how you want it to "feel" when the player moves the Player character. 🙂 Whenever I create games on my own, I always ask myself... "should my player be affected by other gameobjects?". Like for example if an enemy shoots my player, should my player bounce back? Or will I be doing a lot of platforming where the environment should affect my players movement? Then I would use AddForce. Celeste is a good example here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-70d9irlxiB4.html&ab_channel=PlayStation I would only use Velocity if I'm creating a top down RPG, where my character ONLY moves if I tell it to, and will keep standing still no matter what happens to it. Stardew Valley is a good example here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ot7uXNQskhs.html&ab_channel=ConcernedApe But you are right, AddForce does also make your gameobject "slide" around the place. ⛷ However if anyone tells you that "you shouldn't use AddForce because your player slides", then they clearly don't know how to use AddForce properly hehe. 🙂 I OFTEN hear people say they avoid AddForce because of the sliding, and then they instead try and mimic AddForce by using Velocity instead... but that is a mistake since you can VERY easily change how much sliding there needs to be using AddForce. Here are 5 ways on top of my head, to change the AddForce "sliding": - You can add a PhysicsMaterial to the ground or the player, to change the friction on surfaces. - You can change the Liniear Drag in the RigidBody component inside Unitys Inspector. - You can create a "Velocity check" using code, so that your AddForce should stop working after the player reaches a certain Velocity. - You can dampen your AddForce using code. - You can change the ForceMode on your AddForce. So to sum it all up... You should use AddForce when you wan't your character to be affected by other gameobjects, and yes you CAN change the "sliding" very easily in various ways. 🙂 Don't use Velocity if the excuse to do so, is that you don't like your character "sliding", because you can EASILY create responsive movement using AddForce. 👌
@@Dani_Krossing Wow! thanks for the super detailed reply, and I actually learned more as a bonus! Looking forward on your future Unity and C# contents.
Every ti a friend of mine ask to teach them how to use soft soft I share them the link to tNice tutorials YT video tNice tutorials helped so it will help
PLEASE HELP! I'm at 25:00 and my player isn't moving. No key makes the player go left or right. My code is identical to what he's typed in the video. I'm not sure what I'm doing wrong..
Either your script isn’t on your player, or you forgot to add a component to your player, or you made a typo in your code. 🙂 It’s one of those three. I constantly get comments from people who “followed my code exactly”, and then later it turns out they had a typo… You are more than welcome to share your player script here. 🙂
hi ik this yt videos 2 years old but could someone help with a lil issue when i have walls near my player it goes straight up and treats it like ground
I want to just say, thank you so much for actually explaining how or why things work as well as the term definitions. This is literally the only channel I felt like I was learning something new, like a lesson rather than a guide or demonstration.
@@Dani_Krossing im getting the " Top-level statements must precede namespace and type declarations. " error and i would know if i did the code right if you pasted the code into your descripton but you didnt.
It means you added in 3 arguments inside the Vector2(), when it should be 2. I’m guessing you made a typo when it comes to the () you added. In my video, I only added 2 arguments as well. 🙂 So look at the Vector2() part, and compare it with mine in the video.
@@Dani_Krossing thank you for the help, but i still dont know why its not working as i typed everything the same... void FixedUpdate() { if(moveHorizontal > 0.1f || moveHorizontal < -0.1f) { rb2D.AddForce(new Vector2(moveHorizontal, 0f * moveSpeed, 0f), ForceMode2D.Impulse); } } }