Тёмный

Better Jumping in Unity With Four Lines of Code 

Board To Bits Games
Подписаться 41 тыс.
Просмотров 820 тыс.
50% 1

Eliminate the low-gravity feeling of a physics based jump with four lines of code. Actually, just two lines. The other two give you the ability to control jump height based on how long you hold the jump button.
Inspired by the following GDC talk: • Math for Game Programm...
Support Board to Bits on Patreon:
/ boardtobits
Check out Board To Bits on Facebook: / boardtobits

Наука

Опубликовано:

 

19 мар 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1 тыс.   
@fredg8328
@fredg8328 6 лет назад
That is only because gravity is different in Japan.
@mikeluna2026
@mikeluna2026 6 лет назад
It's part of animation principles.You usually want to exaggerate weight, even if it's not realistic per se. It's more about how good it looks or feels.
@taintedmyth0s636
@taintedmyth0s636 6 лет назад
Can confirm, I've been to Japan.
@pspcoder6875
@pspcoder6875 5 лет назад
XD
@pspcoder6875
@pspcoder6875 5 лет назад
lmao @@flamurgoxhuli6099
@pspcoder6875
@pspcoder6875 5 лет назад
principles.You is a link XD @@mikeluna2026
@atilacorreia
@atilacorreia 4 года назад
Very nice tutorial. A little optimization tip: You should multiply your scalars first and then multiply by the vector at the end, or use parenthesis to isolate your scalar multiplications, to avoid extra Vector2 creations. Also, once you're satisfied with your gravity value you can cache Physics2D.gravity.y * (fallMultiplier - 1) and Physics2D.gravity.y * (lowJumpMultiplier - 1) to avoid this unnecessary math on Update. Cheers!
@Gyozamang
@Gyozamang Год назад
can you give that as an example for all the beginners? It's too technically spoken. I tried implementing what you said but i break things
@phoenixanton
@phoenixanton Год назад
@@Gyozamang He means that if you like how your jump is looking, you can just calculate the gravity.y * (fallMultipilier - 1) or (LowJumpMultiplier -1) like done in the code and write it as one number so the program does not have to do this math which is unnecessary because it does it every frame. You could store the calculation in a variable or something like this and let it calculate in Start() so it doesnt do it every Frame. Except you want to change the multipliers during the game like through power ups or such things (dont ask me why you'd need to have a power up for falling faster... but let's say you were like on another planet and needed to fall faster or slower, then its probably better). So to sum it up, you can store it in a variable in the beginning or, if it changes during one scene, you have to let it stay like it is in the video. Hope that helped
@ujjawalsaini780
@ujjawalsaini780 Год назад
@@Gyozamang Bro just apply brakets around constants . Ex Vector2.up * (speed * factor * Time.deltaTime);
@LeviG
@LeviG 2 года назад
I'm still looking this video up every time I'm trying to make a 2D platformer. So simple and useful.
@stylie473joker5
@stylie473joker5 2 года назад
nice
@devmarboy4045
@devmarboy4045 2 года назад
samee
@skm5526
@skm5526 5 лет назад
Very nice explanation. Those who are taunting about video length. Please pay attention his explanation as they were detailed and he pointed the problems with usual unity script. So keep up the good work dude. :)
@Broockle
@Broockle 5 лет назад
wow, rarely do I find code this comprehensible. Good job explaining not only the code but also the whole jumpiness ^^ You're Awesome
@aegresen
@aegresen 6 лет назад
I don't know how RU-vid knew I was having a problem with this but damn, exactly what I needed! Thanks so much!!
@Seraian1
@Seraian1 4 года назад
I always thought the jump was weird, and I did the exact same things you said we would probably do. So thanks, this video was a godsend!!!
@the_original_jake
@the_original_jake 2 года назад
Absolutely incredible tutorial. so simple, was struggling to figure out why my jump felt "off", then finally found your video. Explanation was on point, very clear and well presented.
@mazzikin
@mazzikin 5 лет назад
I have watched multiple tutorials for Unity, and all of them have been so confusing. Your video here has made so much sense to me. Thank you.
@Beanilikecheeeese
@Beanilikecheeeese Год назад
same i now it is 3 years ago you uploaded this but do you still code
@mazzikin
@mazzikin Год назад
@@Beanilikecheeeese I’ve since moved to Godot rather than Unity, but I still code with my favorite web languages. How come?
@good6894
@good6894 6 лет назад
Thanks for the tutorial, well explained, without saying a bunch of extra unnecessary/not-quite-on-topic stuff!
@sameerchitley6968
@sameerchitley6968 6 лет назад
This is awesome! I've tried implementing jumping using Phaser (instead of Unity) in a web game, and ran into the same issue. The theory behind this still holds true and perfectly translates over. Thanks!
@blyth9310
@blyth9310 2 года назад
I think this works really well when you let the player decide when they want to fall faster. It makes you feel really in control of how you move. Great vid!!!
@leofisher1280
@leofisher1280 6 лет назад
4 lines of code. 12 minutes 46 seconds = 766 seconds = 0.005 lines/second
@iansarmiento23
@iansarmiento23 6 лет назад
umm no... 191.5 seconds/line
@scrmnthn5233
@scrmnthn5233 6 лет назад
Christian Sarmiento he did lines/second, you did seconds/line. They’re reciprocals. Do 191.5^-1. You’re both right
@isaiahdaniels5643
@isaiahdaniels5643 5 лет назад
So just like real life programming? #Procrastination
@rc0d3
@rc0d3 5 лет назад
Programming is 4 minutes programming and 30 minutes thinking :D
@christianthompson1839
@christianthompson1839 5 лет назад
@@rc0d3 correct. Very correct.
@AndyTheNoqui
@AndyTheNoqui 7 лет назад
Thanks! I could use it for my lil 3D isometric prototype and jumping feels so much better now!
@MrYanissab
@MrYanissab 3 года назад
Plzzz how did you do it ?? :) How do you change the Physics2d.gravity ? Thank you !
@thewhale2307
@thewhale2307 4 года назад
OMG Thank you sooooo much. This was just the video I was searching for a few hours now. I had two problems with my jumping and I was hoping it would fix maybe one of those. Not only it fixed both but your code is so simple and shot. You are my todays hero...
@MarkIn4D
@MarkIn4D 5 лет назад
I really enjoyed your detailed explanation on why those jumps feel more natural to us. Nice work!
@unfa00
@unfa00 4 года назад
I've recently solved this problem in Godot 3 in a 3D platformer. I've implemented this differently - the player measures the time between the key press and release and there's a maximum afterburner time defined (about 0.5 s). During that time if the jump key is still depressed I apply additional upward velocity which ramps from 100% to 0% over the maximum afterburner time. This provides a very smooth and natural-looking yet expressive jump, it's pretty flexible to balance and doesn't mess with gravity
@Scoin0
@Scoin0 6 лет назад
Holy crap man, I’ve been thinking of trying to recreate Mario World 1-1 as my first project to help me get a better grasp at game development and this helped me out a ton. Every time I wrote some form of jumping mechanic it felt too floaty and unmario like I just couldn’t wrap my head around it. As l was watching your video the ideas and solutions became clear to me. Thanks man.
@Laiser
@Laiser 6 лет назад
Hi.
@Laiser
@Laiser 6 лет назад
Do you know me?
@Scoin0
@Scoin0 6 лет назад
I don't think so?
@Laiser
@Laiser 6 лет назад
Scoin0 Oh it’s okay. I just want to make a friend .
@JuazNeto
@JuazNeto 6 лет назад
This is the most useful jump script I've seen so far. Thank you very much
@CombobreakerDe
@CombobreakerDe 4 года назад
It took a while to implement this for me (cause of the existing script) but man, jumping feels a whole lot better now. Thanks.
@StephanReilly
@StephanReilly 6 лет назад
Hey thanks for the tutorial! Made my jumps a lot nicer, although I had to do some moving around for the "else if" statement as I had animations playing and such :)
@MaharbaRacsoChannel
@MaharbaRacsoChannel 5 лет назад
Thanks for this video, man, it helped me a lot. I saw the debate in the comments about the way you did it and I wanted to elaborate on the right way to implement this ideas. The thing with implementing acceleration in a simulation is that real life doesn't work in the same way: physics simulations work by taking little steps advancing in time, while time in real life is continuous; there are no steps. It's actually very hard to know where an object is going to be in real life, even if you know it's velocity, acceleration and current position, because its velocity changes every instant. What we do in video games to aproximate that effect, where physics have to be calculated very fast, is to take as many little steps as we can in our simulation in time and sometimes we also try to retroactively interpolate the position based on current acceleration. It's enough, but it's not perfect. So, the problem with doing the acceleration in the update is that, when the number of steps taken (the frame rate) is different, we end up with different positions. In this example, we end up with different short jump heights in different frame rates, which is not nice. So, here's what we can do: We create an additional variable, a boolean for storing the state of the jump button, I'll call it jumpPressed. Then, in Update we only have: void Update() { if (Input.GetButtonDown("Jump")) { //there is no problem with changing velocity once in update, //but addforce is better because it conserves momentum, so you can jump in an elevator GetComponent().AddForce(Vector2.up * jumpVelocity, ForceMode2D.Impulse); } if (Input.GetButton("Jump")) { jumpPressed = true; } else { jumpPressed = false; } } Then in fixed update, we can do the same magic: void FixedUpdate() { //Jump dynamics Code if (rigid.velocity.y < 0) { GetComponent().velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.fixedDeltaTime; } else if (rigid.velocity.y > 0 && !jumpPressed) { GetComponent().velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.fixedDeltaTime; } } And tada!
@endasil
@endasil Год назад
If you're multiplying by time.deltaTime in Update, why would you end up at different heights after x seconds depending on framerate?
@MaharbaRacsoChannel
@MaharbaRacsoChannel Год назад
​@@endasil Because even though the acceleration is the same, the increments to the velocity would be distributed differently. Imagine an object that accelerates by 30 meters per second each second. If the simulation was running at 30fps, the first frame the object would move with a velocity of 1, the second frame with a velocity of 2, and the third frame with a velocity of 3. After 1/10 of a second, it would have moved 6/30 of a meter. Now imagine the simulation was running at 60fps. The first frame the velocity would be .5, the second frame 1, the third frame 1.5, the fourth 2, the fifth 2.5, and the sixth 3. After 1/10 of a second, the final velocity is the same, but the object will have moved 10.5/60 of a meter.
@HolyShovelGaming
@HolyShovelGaming 6 лет назад
Works great! Searched everywhere for something like this and somehow this popped up on my recommended page. Creds to you m8!
@lens3973
@lens3973 3 года назад
Great Video! I think it could have been shorter but the clear explanations are great too. This Adds so much To Game Feel and Movement
@Brian-qr2rh
@Brian-qr2rh 5 лет назад
The best jumping tutorial I ever saw in the youtube it made my game even more realistic thanks Board To Bits Games
@YuriNoirProductions
@YuriNoirProductions 7 лет назад
this was so helpful! thank you so much..i was always wondering how to achieve this effect..i knew what the other games did but didn't knew how they achieved it...it bothered me so much because i had that exact thinking problem you mentioned at 3:50...god damn why didn't i found that one out? :D thinking outside of the box at it's finest right here :D Thank you for finally solving that little mystery to me x)
@BoardToBitsGames
@BoardToBitsGames 7 лет назад
Happy to help!
@pastrana2000
@pastrana2000 6 лет назад
This is going to come in handy SO MUCH, especially for game jams where I dont have time to program a non-physics based character controller.
@nicreven
@nicreven 2 года назад
Thanks a lot for the video! I never would've thought about doing it like that, and you did a good job of explaining it.
@tonyrigatoni766
@tonyrigatoni766 6 лет назад
Excellent analysis of Mario's jump and great video. Did you know this is even easier to implement in the latest version of Unity? Rigidbody2D components actually now have a gravity scale parameter which can be modified at runtime. Great stuff, huh?
@book5257
@book5257 2 года назад
Ik it is 3 years later, but does the 3d rigidbody have a version of that now? If yes how would I use it?
@tonyrigatoni766
@tonyrigatoni766 2 года назад
@@book5257 hey there. So, I'm more of a 2D game developer. I don't really work with 3D very much. I also no longer use Unity. Best of luck, though!
@book5257
@book5257 2 года назад
@@tonyrigatoni766 it's ok. Thanks for replying though. I never expected a response this fast
@theentirepopulationofsyria
@theentirepopulationofsyria 7 лет назад
Interesting and explained well. Also, I watched your Black Hole shader tutorial and loved it. There aren't really a lot of shader tutorials on RU-vid for shader noobs like me. Could you please do more shader tutorials?
@BoardToBitsGames
@BoardToBitsGames 7 лет назад
Harshit Dubey thanks! I'm honestly not that familiar with shaders myself; I would recommend checking out Making Stuff Look Good for Unity Shader tutorials, though I will try to do a Shader 101 video sometime in the future (just the very basics, like the class structure and some useful keywords)
@MidnightSt
@MidnightSt 6 лет назад
no need anymore, really. download unity 2018 beta, it has visual node-based shader making, similar to UE.
@CHONK-Music
@CHONK-Music 4 года назад
Super helpful tutorial. I've still got some fine tuning to do, but it's massively better already.
@Kudoshi
@Kudoshi 3 года назад
Really loved your explanation. I like how you explain the problem and then the solution. Then only give the codes and explaining further about the codes.
@masacote_
@masacote_ 6 лет назад
"Jump into the jump scrpit" -Board To Bits Games 2017
@donnythedingo
@donnythedingo 6 лет назад
Every time I see this type of video it makes me appreciate how genius Nintendo is for figuring this out decades ago, without an engine like Unity.
@ananttiwari1337
@ananttiwari1337 3 года назад
And they made it in Assembly x86!
@logicalapple_3274
@logicalapple_3274 3 года назад
the quality of this tutorial is so good
@katehinkel8670
@katehinkel8670 5 лет назад
Thanks a lot for your geneious trick! I've been looking for solution of my 'realistic' jump whole day and finaly found yours! :D
@radicalappdev
@radicalappdev 5 лет назад
I used this in the opposite, to reduce the effect of gravity. This lets the player glide a bit after the jump. rb.velocity += new Vector3(0, rb.velocity.y * Physics.gravity.y * 0.5f * Time.deltaTime, 0);
@Altimicus
@Altimicus 6 лет назад
Nice work, I'd just separate the input in Update, hold the jump button state in a variable and do the physics in fixedupdate otherwise, you risk accelerating too much or too little depending on your frame rate. I'd also use AddForce with ForceMode.velocityChange instead of summing directly to the velocity, since that takes care of collisions in a better way avoiding you to go through things by directly setting the velocity vector.
@dusansimic1907
@dusansimic1907 5 лет назад
Thank you so much! That explanation at the beginning was excellent!
@DavidMauas
@DavidMauas 5 лет назад
This is great. I love your channel. I believe it is precisely THESE types of tweaks, that make a game worthwhile. When I grab a controller, and I get the FEEL for the game - it is these curves - the curves of the functions - that my body really is getting a feel for Perfecting this sort of innuendos IMHO is the way to create really good games. Look forward to going over all your video library. One at a time :) Thanks for posting.
@CracksisT
@CracksisT 7 лет назад
Wouldn't it be better if you placed the code in FixedUpdate instead of the regular Update, since you're tampering with the physics?
@BoardToBitsGames
@BoardToBitsGames 7 лет назад
It's tricky. Because you're looking at Inputs, Update is preferable, but in general, when affecting physics, FixedUpdate is preferable. You'd probably want to do some optimization before shipping, but for getting you to a better jump feel quickly, I think this is OK in Update.
@kippetjetoktok
@kippetjetoktok 7 лет назад
I would disagree, you should aim to NEVER change physics in Update. Changing the code is as simple as getting the button state in the Update() function and keep the result in a boolean. Then using that in FixedUpdate.
@BoardToBitsGames
@BoardToBitsGames 7 лет назад
If it were adding force I would agree with you 100%, because you risk adding more or less force based on framerate, but setting the gravity to a flat value is a little less troublesome.
@SaisBlade
@SaisBlade 6 лет назад
I know updating physics in FixedUpdate is considered best practice, but why would you be adding more or less force in Update w/deltaTime rather than FixedUpdate w/fixedDeltaTime? the force you add should be constant either way (per given time)
@lucasmontec
@lucasmontec 6 лет назад
It is wrong and you should just accept it. You should detect the inputs in Update and handle them in the fixed. Don't change stuff outside the physics loops. In the best case you are wasting processing, in the worst you are doing stuff that is related to the framerate (or worse).
@andrewromitti2038
@andrewromitti2038 4 года назад
I love programming! There’s just something about creating the brain for an awesome project that makes me can’t wait for my future classes in coding
@Berryss
@Berryss 7 лет назад
1st Video im watching from you. Already subbed since you explain really well. Keep it up!
@joshlovesfood
@joshlovesfood 4 года назад
Excellent video with excellent observations and details, thank you very much for sharing!
@user-dm5qi4nb6l
@user-dm5qi4nb6l 3 года назад
how to do this with the new input system? I'm having troubles trying to move and jump using 2D physics
@Hawkadium
@Hawkadium 6 лет назад
None of my characters can jump. Still enjoyed learning this technique, thank you.
@roguegamingvoid4854
@roguegamingvoid4854 3 года назад
see if the massssss is tooo high lul mine was doing the reverse it fly for ever and als this progam let my char to jump multiple times
@blacksaibot6158
@blacksaibot6158 5 лет назад
This is FANTASTIC. Thank you!
@GimmeSomeDosh
@GimmeSomeDosh 11 месяцев назад
Genius! Thank you, very much. You solved one million problems on my brain and gave me a perfect gimmick to implement!
@Sylfa
@Sylfa 6 лет назад
Okay, your doing `v += gravity` in the jump and `v += gravity * multiplier` in the fall, but that equals: Jump: v += gravity + jumpHeld ? jumpAcceleration : 0 Fall: v += gravity And just a higher base gravity. You didn't want to add to the velocity in the jump (while jump held, add acceleration) and then spent a whole lot of time just rewriting the problem from a different reference frame. But in the end it's the same thing. Your adding a jump acceleration during the jump if the button is held, by manipulating the gravity afterwards. I suspect you will get a better correlation with marios jump if you just apply a force while the button is held anyways.
@laurencehonok608
@laurencehonok608 3 года назад
how does this work on the new inpute system
@siroccomask
@siroccomask 5 лет назад
Thanks for this video. From your implementation, I realized just now that you can have multiple scripts on a single object. This seems like a good way to augment the effects without having a huge character controller.
@BoardToBitsGames
@BoardToBitsGames 5 лет назад
It sure is. It also allows you to swap features or abilities in and out dynamically without using extensive condition checking
@luizguilhermepelegrini8297
@luizguilhermepelegrini8297 7 лет назад
Great quick tutorial and very well explained, cheers mate!
@SemperFidelisGames
@SemperFidelisGames 7 лет назад
The amount of views your getting is criminal, something this useful should be way higher.
@BoardToBitsGames
@BoardToBitsGames 7 лет назад
+Jacob Luiten thanks!
@JorgetePanete
@JorgetePanete 6 лет назад
Jacob Luiten you're*
@seemoore9175
@seemoore9175 4 года назад
4:32 its actually suprisingly simple.
@cathacker13
@cathacker13 4 года назад
All we have to do is to put a muncher on tracks and then use the red coin to change the memory into a state where it will overwrite it with a lit bob-omb
@Rioni
@Rioni 4 года назад
Wow, I wasn't expecting a Ceave Gaming reference here xD
@JagiUGG
@JagiUGG 4 года назад
bruh
@manperson1119
@manperson1119 4 года назад
Rioni same here lol
@loljay3281
@loljay3281 3 года назад
Hey I know that reference
@pip.turner
@pip.turner 7 лет назад
golden tutorial. Knew exactly what I needed to do before it, came away knowing more and knowing how
@torinsteil4487
@torinsteil4487 4 года назад
Such a good video, this really helped me. Your doing good and I hope you post more. Subscribed!
@codewarrior8426
@codewarrior8426 4 года назад
The issue with your implementation is that when my character is walking up hill it triggers the condition of low jump and makes it very hard to walk up the hill, so maybe there needs to be some tighter condition checks for low jumping.
@lighterasd
@lighterasd 4 года назад
You can set a collider on the character, and make a "GroundCheck" script for it
@Tako40404
@Tako40404 5 лет назад
Wow, these comments are salty! Thanks for idea, I'm going to use it in UE4 :)
@DukensteinA1
@DukensteinA1 2 года назад
This video was excellent. Great content and superb presentation! Thank you for making it.
@yungnut4247
@yungnut4247 6 лет назад
I had always wondered why the jumping in my games felt so wrong, thanks for this!
@knospi
@knospi 6 лет назад
Nice trick using gravity scale. This could benefit from some improvements: * no physics updates in update, use FixedUpdate (otherwise the physics is dependent on the framerate) * d̶o̶n̶'̶t̶ ̶m̶a̶n̶i̶p̶u̶l̶a̶t̶e̶ ̶v̶e̶l̶o̶c̶i̶t̶y̶ ̶d̶i̶r̶e̶c̶t̶l̶y̶,̶ ̶a̶l̶w̶a̶y̶s̶ ̶a̶p̶p̶l̶y̶ ̶f̶o̶r̶c̶e̶s̶ ̶(̶o̶t̶h̶e̶r̶w̶i̶s̶e̶ ̶y̶o̶u̶ ̶m̶i̶g̶h̶t̶ ̶g̶e̶t̶ ̶p̶r̶o̶b̶l̶e̶m̶s̶ ̶w̶i̶t̶h̶ ̶t̶h̶e̶ ̶p̶h̶y̶s̶i̶c̶s̶ ̶e̶n̶g̶i̶n̶e̶)̶
@evanmedi6144
@evanmedi6144 6 лет назад
what u mean by the second part, i shouldn't be using velocity for jumping?
@sutirk
@sutirk 6 лет назад
Knospi So no using "rb.velocity += stuff;", huh? Is the safe way to use "rb.ApplyForce(0,stuff,0, ForceMode.velocity);"?
@knospi
@knospi 6 лет назад
It's also used in unity documentation.
@evanmedi6144
@evanmedi6144 6 лет назад
+knospi i always thought that Add.force is better used for bullet movements and lunching pads per example meanetime rb.velocity is suited for player movements
@knospi
@knospi 6 лет назад
nah
@VictoriaStobbie
@VictoriaStobbie 6 лет назад
"We can actually solve both of these things by manipulating one thing...Gravity". The movie. I fucking knew it, never that easy.
@therealgamewizerd
@therealgamewizerd Год назад
such a simple fix but man does it ever make a difference. Great work!
@rrrush
@rrrush 7 лет назад
thanks so much i didnt know how to script this on my own, this helped me understand the physics and velocity a bit more in c script. thank uand good vid keep up the good work.
@derekw8039
@derekw8039 3 года назад
4:31 "...show the what's actually surprisingly simple code..." My brain: Hears Ceave Gaming: "The answer is *surprisingly simple!*"
@TheGios100
@TheGios100 6 лет назад
People if you want to make a simple code for the character to jump only in the ground, use Raycasting instead of OnCollisionEnter, i used it and i reduced the amount of code significantly and got a better result
@JordanMetroidManiac
@JordanMetroidManiac 6 лет назад
I use the following method to check whether my game character is standing on a solid object. I created the boolean field "grounded" so that the code can check for that to be true before adding any forces to the RigidBody2D. Others might need to change the 1.01 offset on the y position while 0.01 is an appropriate maximum distance for the raycast. void CheckGrounded () { RaycastHit2D hitInfo = Physics2D.Raycast (new Vector2 (transform.position.x, transform.position.y - 1.01f), Vector2.down, 0.01f); grounded = hitInfo.collider != null; }
@knifeyonline
@knifeyonline 6 лет назад
and on what conditions do you set the grounded bool?
@butterflytr3077
@butterflytr3077 2 года назад
This video is perfect for everyone. I'm a beginner in programming and even I could understand it easily. It is very optimised too.
@kennethringo
@kennethringo 4 года назад
Using this in my game. Thanks a lot for explaining really well and really dissecting the jump mechanic in Mario.
@KuraIthys
@KuraIthys 6 лет назад
Mario's jump physics is pretty weird. (and complex.) Not only does he go up faster than down, but your rate of descent varies depending on whether you hold the button down or not. (as do other parameters of the jump) And of course, you have a large degree of air control. (now, contrary to what you might think, in reality you also have air control, but mostly over your angular momentum, less so over linear motion.) There's a lot of factors here that aren't based on reality...
@vilkillian
@vilkillian 4 года назад
9:37 Why don't just scale the gravity? Rigitbody even have a variale for that
@TheHuesSciTech
@TheHuesSciTech 4 года назад
Because that would be a utterly disgusting hack that had unintended effects on the rest of the objects in the game? (I've never used Unity so maybe I'm wrong)
@80ruta89
@80ruta89 4 года назад
@@TheHuesSciTech No, you can set gravity scale for only one object beacose every object have it's own rigidbody2d component. Sorry for bad english. ^^
@TheHuesSciTech
@TheHuesSciTech 4 года назад
@@80ruta89 I stand corrected, thank you. Yours seems like a much more elegant solution with that in mind.
@Neku109
@Neku109 7 лет назад
Good video! Been looking for something like this for a while.
@james199522
@james199522 5 лет назад
Great video man, really appreciate the knowledge!
@dean8235
@dean8235 6 лет назад
12 minutes 4 lines of code
@raspberry_picker395
@raspberry_picker395 6 лет назад
More than 4
@ro734
@ro734 6 лет назад
I actually felt it wasn't that long. He first identified the problem, made a solution based on a talk, explained the solution and wrote the code. If he just wrote the code, it would have definitely be shorter, but then you would not have understood it as well, or at least less skilled programmers wouldn't
@ArnoldsKtm
@ArnoldsKtm 6 лет назад
Would "take these 4 lines and think for yourself why" be a better video?
@dennis8832
@dennis8832 6 лет назад
Beginner here, thought the video was of good length. :)
@Jus_Joj
@Jus_Joj 6 лет назад
Well I mean he could have just told you what the code was and you could have copied it and learned next to nothing, but noting how impatient you seem to be, I doubt you learned much anyways.
@leg-sc1bb
@leg-sc1bb 6 лет назад
its not working 4 me
@FirstVaultDweller
@FirstVaultDweller 3 года назад
This is one of the best simple tut for jumping so far for me, Thank you. definitely gonna sub 🙂👍
@mateoalvarellos5263
@mateoalvarellos5263 3 года назад
Thanks for the video! I was struggling hard with the jumps and this helped a lot.
@bckb604
@bckb604 6 лет назад
There's a big problem here. If you keep clicking and letting go of the space bar over and over again you can jump forever.
@mysteriodark9686
@mysteriodark9686 6 лет назад
Do a downward raycast to check if your player is grounded before jumping is allowed
@marscaleb
@marscaleb 6 лет назад
I have points on the bottom of my character that check if they intersect with the ground.
@Prox_C
@Prox_C 6 лет назад
iterate a counter every time the key is pressed and you could set a fixed number of mid-air jumps that reset again on floor collisions. you could have double jumps/glides etc with very little work. better than onStay() intersect methods.
@jiexiangshen5839
@jiexiangshen5839 6 лет назад
you need add GROUND CHECK for your player
@lonttugamer2939
@lonttugamer2939 5 лет назад
Just check if the player is colliding with the ground with OnCollisionEnter2D(), u might have to play with tags depending on what way u do it
@MrScylesToYou
@MrScylesToYou 4 года назад
This is good and all but why would you just not make the multipliers 1.5 and 1 instead of having an extra step of subtracting 1 anyway
@technorazor976
@technorazor976 4 года назад
It's not about how easy it is to type, it's about the actual meaning of the value. In order to multiply gravity by a certain amount, you have to subtract 1 from the multiplier to get what percent *more* gravity you need to add after the Unity engine already applies the gravity. The reason why we don't just subtract 1 in the first place is because the property would no longer have the same meaning; a multiplier of 1 implies that gravity would stay the same, but with your idea that would mean actually doubling the gravity. If you really wanted to, you could have the variable represent the percent change in gravity rather than the multiplier, but it's good practice to have consistency in your code that would make sense to anyone else reading your code.
@MrScylesToYou
@MrScylesToYou 4 года назад
@@technorazor976 yeah but what he says doesn't make sense anyway and those are just numbers he plugged in, he may think/mean he is doubling the gravity but he isn't. By subtracting 1 he is just multiplying it by 1 which makes the variable there redundant. Same with the 2.5, what he means is not what he is actually doing with the subtraction of 1. It's basic math...
@technorazor976
@technorazor976 4 года назад
MrScylesToYou The Unity engine already applies 1x gravity, so to double the gravity you have to add 1x the gravity to the velocity again, making 2x gravity total, get it?
@technorazor976
@technorazor976 4 года назад
MrScylesToYou Also, 2 and 2.5 were arbitrary numbers that he decided felt right. If you wanted to change them, you just have to change the number in the inspector. The variable isnt redundant, it's there to be potentially changed.
@NuNaKri
@NuNaKri 4 года назад
Wow ok! I'm very impressed by the work you put in this. Thank you :D
@BOMBCUBES
@BOMBCUBES 10 месяцев назад
This is exactly what i've been looking for. Thanks man
@denissachkov6693
@denissachkov6693 6 лет назад
you can just use gravityScale of rigitbody for this in 1 line of code
@kaldrax1
@kaldrax1 6 лет назад
That's what I thought he was gonna do when he started talking about changing gravity XD
@BoardToBitsGames
@BoardToBitsGames 6 лет назад
Good point! However, you do still need the other lines to cover which gravityScale to apply; but it is a much cleaner approach.
@JohnnyThousand605
@JohnnyThousand605 6 лет назад
Agreed. Changing the global gravity seems like a sledgehammer solution as it may cause some undesirable effects with other objects, possibly even NPCs. To be honest I'm curious why gravityScale is only for 2D rigidbodies, but whatever.
@hasagine3479
@hasagine3479 6 лет назад
I can write an entire game in 1 line of code...
@pierrestempin100
@pierrestempin100 6 лет назад
Yes but that line could be very long (and depending on how your game is complex). An entire game in one line is possible but not practical at all.
@CredixNetwork
@CredixNetwork 6 лет назад
print("Hello, world!");
@Joseph-gq9nd
@Joseph-gq9nd 6 лет назад
private void Update() { UpdateGame(); } private void UpdateGame() { // GAME CODE HERE }
@giakomoventura2088
@giakomoventura2088 6 лет назад
You can't do that because of #include ....
@hazel6221
@hazel6221 6 лет назад
Beat me to it
@heavy5756
@heavy5756 5 лет назад
Beatiful, simple and usable, thank you
@Kholdster
@Kholdster 4 месяца назад
This video was so helpful! I used it to add to the Philippe St-Amand Kinematic Character Controller.
@ryanreed4698
@ryanreed4698 6 лет назад
"Better Jumping in Unity With Four Lines of Code" - 12 minute video
@dmas7749
@dmas7749 4 года назад
was never a fan of mario 1's jump arc i play a lot more of castlevania
@pedroribeiro9746
@pedroribeiro9746 4 года назад
no air movement gang
@dmas7749
@dmas7749 4 года назад
@@pedroribeiro9746: i'm fine with either tbh mario 1's arc does bother me even compared to other marios
@NikkiMcMistie
@NikkiMcMistie 6 лет назад
This is so helpful. I learned a new method for jump. Thank you very much.
@kapilverma3273
@kapilverma3273 5 лет назад
Thank you very much. My player's jump looks really cool now.
@kdhlkjhdlk
@kdhlkjhdlk 6 лет назад
12 minutes for four lines, what the fuck is going on?
@Toads
@Toads 6 лет назад
4 lines of code in 12 minutes...
@hijosdeputa1000
@hijosdeputa1000 5 лет назад
I've watched like 8 jump tutorials (brackeys, blackthornprod, code monkey and others) and yours is the best and most reasonable yet (Y)
@DrewofDonuts
@DrewofDonuts 5 месяцев назад
I know this is an old video, but it certainly helped to improve my jump. Thank you!
@LettuceBunnies
@LettuceBunnies 6 лет назад
What you described had nothing to do with "lines of code".
@justcore
@justcore Год назад
Now this is a legendary video
@thomasjensen9581
@thomasjensen9581 6 лет назад
wow thank you bro, you just got another sub keep up the awesome and quick learning work :D
@KirbzXXX
@KirbzXXX 2 года назад
This is an excellent analysis, thank you
@Archgamer
@Archgamer 4 года назад
Excellent video my dude.
@hevet
@hevet 2 года назад
I just love this. Thanks a bunch!
@albertross2254
@albertross2254 6 лет назад
I love these kinds of videos.
@Oxmond
@Oxmond 4 года назад
Wow! Really great JUMP tutorial! Well done! 👍🤓
Далее
Better Jumping in Unity: Optimizations
10:07
Просмотров 44 тыс.
QVZ PREMYER LIGA
00:18
Просмотров 1,6 млн
Flo Rida - Whistle НА РУССКОМ 😂🔥
00:29
How to make Music for your Game - BOSCA CEOIL
11:20
Просмотров 801 тыс.
5 tips for better platformer controls
5:22
Просмотров 197 тыс.
How to jump in Unity (with or without physics)
16:09
Просмотров 42 тыс.
Math for Game Programmers: Building a Better Jump
25:43
Recreating Celeste's Movement | Mix and Jam
5:47
Просмотров 234 тыс.
Coyote Time & Jump Buffering In Unity
3:48
Просмотров 76 тыс.
How to make AWESOME Scene Transitions in Unity!
19:45
Просмотров 928 тыс.
Secrets to a Great Platformer Character with Unity
3:11
iPhone 15 Pro в реальной жизни
24:07
Просмотров 446 тыс.
Красиво, но телефон жаль
0:32
Просмотров 1,5 млн
АЙФОН Г0ВН0
0:54
Просмотров 1,3 млн