hi i'm korean -this sentence is Google Translator I was almost giving up implementing this function thank you so much for tutoring this function. I wish you more subscribers. ^^b
hi korean -this sentence is Google Translator I was almost giving up implementing this function thank you so much for tutoring this function. I wish you more subscribers. ^^b im sugar
Excellent tutorial dude. I don’t really have any specific requests right now but keep it up your killing it right now with these vids. Dare I say overtaking brackeys as one of the best unity youtubers atm.
If your character gets stuck on a wall when you touch it, make a new Physics Material 2D in your assets, then set the friction to 0, and add it onto the collider on your player. :)
That's the worst I remember, when I was a Uni-noob, spending Weeks following a 14 part tutorial that left me with just this garbage code, that i didn't know (at that time) how to fix. I feel your struggle.
Here is some improved code that fixes a double jump bug and adds cool fall physics as well as better organization. I got the cool fall from a video called better jump with 4 lines of code. I recommend values of 2 and 2.5 for the fall multiplier variables. using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { [Header("Components")] private Rigidbody2D rb; public float speed; public float jumpForce; private float moveInput; [Header("Layar Mask")] private bool isGrounded; public Transform feetPos; public float checkRadius; public LayerMask whatIsGround; [Header("Jump")] private float jumpTimeCounter; public float jumpTime; private bool isJumping; [Header("fall physics")] public float fallMultiplier; public float lowJumpMultiplier; //Gets Rigidbody component void Start() { rb = GetComponent(); } //Moves player on x axis void FixedUpdate() { moveInput = Input.GetAxisRaw("Horizontal"); rb.velocity = new Vector2(moveInput * speed, rb.velocity.y); } void Update() { isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround); //turn twords you go if (moveInput > 0) { transform.eulerAngles = new Vector3(0, 0, 0); } else if (moveInput < 0) { transform.eulerAngles = new Vector3(0, 180, 0); } //cool jump fall if (rb.velocity.y < 0) { rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime; } else if (rb.velocity.y > 0 && Input.GetKey(KeyCode.Space)) { rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime; } //fixed double jump bug if (Input.GetKeyUp(KeyCode.Space)) { isJumping = false; } //lets player jump if (isGrounded == true && Input.GetKeyDown("space") && isJumping == false) { isJumping = true; jumpTimeCounter = jumpTime; rb.velocity = Vector2.up * jumpForce; } //makes you jump higher when you hold down space if (Input.GetKey(KeyCode.Space) && isJumping == true) { if (jumpTimeCounter > 0) { rb.velocity = Vector2.up * jumpForce; jumpTimeCounter -= Time.deltaTime; } else { isJumping = false; } } } }
it gives me this error plz help NullReferenceException: Object reference not set to an instance of an object PlayerMovement.Update () (at Assets/finshed scripts/PlayerMovement.cs:49)
This is the earliest I've ever been. This is because this is the second video I've watched since I've subbed. I watched lots of older videos & newer ones & I decided to subscribe. Thank you so much for all the help. This channel is awesome. I hope to see you continue doing videos.
Your video Quality has gone up incredibly I've been watching your videos since the 2D character customizer one of your early videos now your like Super Efficient with your Code and informative. Your videos are Really Good my Friend keep up the Amazing work Noah & Friends I Appreciate It Thank You! 👌👍
I'm trying to do the same thing in Love 2D and your tutorial actually really helped! I finally understand how this sort of jump works and I was able to reverse engineer your code into my Love 2D Lua project. Thank you!
I made a two-month break from making games because I was overwhelmed with the school work and other things I had to do and now when I got back to it I totally forgot the syntax for C# and I was laughing at myself in front of vs screen for 10 minutes straight.
This is incredible well explained, I can notice how much you edit the video to keep it clean and short, but at the same time with a lot of information. Thank you very very much.
Awesome buddy, thanks for doing this video it made the jumping much more interactive and having such a feature adds a bonus layer to the plain action of jumping !
Thank you for making this video. After implementing this code i noticed that the character would do sort of a mini double jump when ascending, I also see this replicated in the beginning of your video. after playing around with the values I found it best to actually set the initial jump as the Max height, and while jumping, instead of adding force when the jump button is held, you'd want to subtract (add a negative) force when the jump button is not held (I added an additional line that would stop the subtraction when I fell below a certain Y velocity, just so i'm not pulled down any faster) the result is more seamless jump, But again I thank you for making this video. I would not have come to this point, if it weren't for you.
I was thinking the same, as it's also a much easier method, that instead of increasing the height while the button is down, just simply increase the gravity to fall faster or add a new force to push down the character when the key is released. But it kinda gives a different feeling to the jump.
nice tutorial, I was actually hoping to get some advice how to animate a jumping animation that uses this system. The hollow knight main character has a jump up and jump down animation followed by a falling and then landing animation I think. And it adapts to the height of the jump.
Thank you for this video.. I was following a tutorial while making my own "Wario land 3" and obviously, it had that Mario jump mechanic.. so I've decided to start again with everything I learned but rather than blindly follow tutorials, I'll use this as my base and the rest I'll use what I learned on the way😘
Why is the reason you use feetPosition + manual "OverlapCircle" instead of using Unity colliders + OnCollisionEnter() and OnCollisionExit()? Maybe at the time of writing you didn't know about it, or is there an optimisation reason?
Hi Great Tutorial and clear articulation. im very new to unity i managed to recreate the code in my project. My question is can it be combined with the previous tutorial's double/triple jump mechanics? can I just copy the lines or do i have to tweak some lines specifically ? thanks
It would be more efficient to check if the player is grounded when you hit the Jump button (in the "if" condition), rather than checking every single frame whether it's needed or not.
But what if you need to check for ground the moment you landed? Like, to set animator triggers. Hmmm, guess then I can do it through function which is called OnCollisionEnter. This would still generate unwanted callback for whatever collider was not ground, but which is more expensive?
This is old, but you should definitely keep Inputs in Update instead of Fixed Update because sometimes the game won't catch the Input quick enough. Great tutorial though!
Very good turotial! I do also have a video suggestion, could you make a tutorial on inventory systems, I've been looking on youtube but all I can find are unfinished tutorial series and although Brakeys' tutorials are good, they seem kinda complicated as I was just looking to use a simple inventory system in a 2d game, but then I thought about you and your great way of making concise and straight to the point videos so I thought I'd leave a comment. Thanks again for all your helpful videos! :)
I love your videos and hope to see more. Quick question, I noticed that you implemented the jump (change in velocity) in the update (not fixedUpdate) method, why? I've seen this in many other videos as well.
Here's a tip for better movement.... On the player, set the "Linear Drag" to a greater value.... in the player script, instead of using" rb.velocity = ...." use "Rb.AddForce(*direction* x *small value*)" I bet there's one little problem now, the jump.... To fix this, go to player script, and check if the feet object overlay is not colliding, if so set normal values of rb, if not, set the "Linear drag" to a greater value
Very good tutorial but why you are detecting input in fixedupdate? You have to detect input in update cause it's more faster and than move if rigidbody attached in fixed update!
Thx so much it was so helpful i was trying to do some player movment but it always give an error💔😂 horizontal input is not setup something like that but that code worked so well thx👍👍👍
Hi Noa, great video as always! I was wondering if there is a chance of you making a tutorial (series?) about 3D character movement? Having mainly 3D platformers in mind such as A Hat in Time, Yooka Laylee and such. Keep up the great work, you're a fantastic educational resource and a great teacher :D
Great turtorial, but you should make sure to multiply your movements by time.deltaTime, or you should put the physics in the FixedUpdate region (saying this because I did the turtorial just like this, and got a bug)
I really want to use it, but i'm having a little problem, if i press jump many times quick, sometimes the character do a "Double Jump", how can i solve it?
@@jankozorbas have you tried to add "&& isJumping = false" to if(isGrounded == true && Input.GetKeyDown("Jump")) like this: if(isGrounded == true && Input.GetKeyDown("Jump") && isJumping = false) haven't tried it I will do so later
That's happening because you have a very large radius on check radius so if you manage to press the space so quick the radius is still touch the ground. Try a smaller number on check radius instead.
Hi Noa, Hey is there a video that show how to move and animate the player left or right but also play a Walk, Run and Sprint animation depending of the moveInput value ? for example if moveinput between 0.010 to 0.030 then play the Walk Animation and apply a Low force to the Right or Left or moveInput between 0.031 to 0.060 then play the Run Animation and apply a Medium Force to the Right or Left and moveInput between 0.061 to 1 then play the Sprint Animation and apply a High Force to the Right or Left
Thank you, bro! I asked you about this several days back! I'm actually surprised it became a video. This will help a lot of people in the future. Thank you so much! :)
Thank you, BlackThornProd. I've been having problems with my feetCollider(BoxCollider2D) and bodyCollider(CapsuleCollider2D). Basically my game's player has two colliders, one for checking the ground and one for the body to detect damages from an enemy. The huge problem was there's an edge that intersects the bottom of the capsule and the top of the box, so whenever I jump at platforms within jump reach, I tend to get stuck at the sharp edge of my platforms. I tried to fix it using Custom Physics Shape by turning my sprites' sharp edges to 45°. Nothing worked so I have to eliminate the box collider somehow, then I found this. Thank you again :>
ive been facing a problem that i didnt manage to fix which lets you jump like 5 times before you stop if you spam the jump key, any ideas on how to fix?
I got a question. Why you say that the player can doublejump in midair at 6:29? jumpTimeCounter is not assigned. So it value is 0. by dafault. You can doublejump in midair if you assign a value to it, bacuase jumpTiimeCOunter became > 0.
doing it this way makes it feel very floaty, like instead of a burst of velocity that goes down as you go up, you start slowly, then go up normally, like youre levitating or like an invisible hand is picking you up. Any way to make the jump feel more jumpy?
This is working, but I can triple jump if i press the space bar quick enough until I reach the peek of the jump. Is there a way to remove that so I cannot spam the spacebar to jump while im in the air?
thanks for video this is so much helpful i am new at game developer and i try to find stop jump animation and how turn my swordman left i found this in your videos thank you Sorry for english i am new in this,too
Can you please do a video on how to animate in unity like your cube for instance, moving up and down in idle, did you export a file from PS as shown on previous videos or is this only animated in unity? I struggle with Idle animations
but i have a problem... my player after he touch the ground the sprite fall a little inside the ground sprite... what is the problem ? i know this problem is a popular problem with 2d character jump ... ( sorry for my english)
Followed along, not sure if a year makes a difference but by the end, I couldn't move while jumping, adding the horizontal movement code in with the if(JumpTimeCounter > 0) fixed it
Hello. I have an issue. When I press the space key, the character jumps, but it can jump infinitely(groundCheck is not working). Also, the "Press space to get a higher jump " is not working for me. Help!!!
Blackthornprod really nice video, this is a "most-wanted" mechanic. One question... why the left/right movement on Fixed but the up/down on Update, both are afecting the rigidbody... ¿shouldn both be on fixed?
I love this tutorial so much, much better then the last one ! ^_^ only problem I had was my camra was also flipping as well? My camra is set to follow my character. Any tips?