How to jump in Unity (with or without physics)

  Рет қаралды 40,260

Game Dev Beginner

Game Dev Beginner

Күн бұрын

Learn how to make an object jump in Unity with or without using physics.
00:00 Intro
01:43 Jumping with physics
03:29 How to fix a floaty jump
05:00 Faster fall jump curves
05:59 Jump to a specific height
06:49 Controlling jump height
09:31 Jumping without physics
10:31 Make your own gravity
11:15 Ground checks
13:38 Ground snapping
14:59 Advanced platforming features
15:38 Outro
You'll learn how to use physics forces to make an object jump, how to create your own physics system manually and how to limit how high and far a player can jump by limiting jump height and measuring the jump button press time.
Read my full article here: gamedevbeginner.com/how-to-ju...
For more on advanced platforming mechanics, try these links:
David Strachan's interactive article: www.davetech.co.uk/gamedevplat...
TaroDev's platform controller video: • Ultimate 2D Platformer...
Credits:
Outro music: New Year by Bad Snacks
Chalkboard image - School rules photo created by kjpargeter: www.freepik.com/photos/school...

Пікірлер: 60
@MyPing0
@MyPing0 Жыл бұрын
Man I really wish all tutorial videos were like this. So professional, straight to the point, and gives examples for various scenarios. Love your work!
@b0b0_
@b0b0_ Жыл бұрын
Found this right before I was about to give up, got it to work at midnight, you my guy are an answer to my prayers 🙏🏾🙏🏾
@GameDevBeginner
@GameDevBeginner Жыл бұрын
So happy to hear it helped you!
@THExRISER
@THExRISER Жыл бұрын
Had to figure this out completely on my own (No physics jumping that is) but I'm glad this tutorial exists nonethless because I know there's definitely a better way to it.
@victrozzz
@victrozzz Жыл бұрын
I really hope your channel blows up. It's quality content that's not only helpful, but very fun to watch. I could binge watch these even if I'm not trying to make a game
@GameDevBeginner
@GameDevBeginner Жыл бұрын
Thanks so much!
@ricardomachado1169
@ricardomachado1169 Жыл бұрын
Amazing tutorial, thanks so much!
@muhammadzubairirshad6724
@muhammadzubairirshad6724 7 ай бұрын
The way of Teach is just amazing
@attilagal6459
@attilagal6459 Жыл бұрын
Uprising Brackeys 2. Keep it up!
@kiel5390
@kiel5390 Жыл бұрын
Always quality videos!
@GameDevBeginner
@GameDevBeginner Жыл бұрын
Thank you!
@ligofleyens9131
@ligofleyens9131 Жыл бұрын
Personally I also like to add the coyote time variable to give those extra millis to trigger when making big jumps from platforms.
@nava.a_rts
@nava.a_rts Жыл бұрын
this is amazing i love u man
@TackleProd
@TackleProd Жыл бұрын
Great video :)
@KindoSaur
@KindoSaur 4 күн бұрын
Not sure if you'll be reacting on this one but I have an issue with the "PhysicsBody-less Jumping Code(?)". Where an IN-engine only bug happens when the player hits the ground whilst the fps is lower than 60fps: First of all. I HATE PRE MADE PHYSICS inside of engines due to the loss of control and unneeded complexity it causes when developing. SO I was really happy to see your video that was able to talk about both of em. Okay the issue I am having is that the player clips straight through the ground, due to the raycast not detecting the ground on time. This only occurs when the FPS is lower than usual (or less stable). What happens is that the distance between each frame of falling becomes bigger and less accurate. Thereby creating the bug that my player falls through the ground eventhough the acceleration is Clamped on a low value, rayCast is set to an immense distance (tested multiple distances) and engine was running at 40 - 60 fps. How will I be able to counter this specific issue? Or what could have been different from your code or setup (think of different Model Collision Shapes etc.)? Also at last; I am working in 3D with a minimalist environment (lowpoly / no active lighting / 5 scripts tops running) thanks
@MarekNijaki
@MarekNijaki Жыл бұрын
Awesome video
@GameDevBeginner
@GameDevBeginner Жыл бұрын
Thanks!
@ristence
@ristence 8 ай бұрын
thx
@2deep215
@2deep215 Жыл бұрын
Finlly thanks dude
@GameDevBeginner
@GameDevBeginner Жыл бұрын
Happy to help!
@rtfranco
@rtfranco 9 ай бұрын
Nice 14:00, but what about slopes (45°, 60°, etc)? How to calculate this offset height in this case?
@chrisswinney9163
@chrisswinney9163 Жыл бұрын
Can you do the jump height cancel on the jump with out physics?
@Nikeyman-ne8fp
@Nikeyman-ne8fp Жыл бұрын
can you please tell me what compiler are you using. It looks so nice
@GameDevBeginner
@GameDevBeginner Жыл бұрын
The visual studio theme is Gruvbox, if I remember right
@samooniyaksaman9509
@samooniyaksaman9509 8 ай бұрын
What is the final solution for slope question?
@alex-ki9et
@alex-ki9et Жыл бұрын
hey! do you happen to still have the code for this? For the part where you alter the velocity of the rigidbody directly
@GameDevBeginner
@GameDevBeginner Жыл бұрын
There are some code examples in the original article if that helps? gamedevbeginner.com/how-to-jump-in-unity-with-or-without-physics/
@acedia4454
@acedia4454 11 ай бұрын
A problem I currently have is the jumping. Since it checks if we are grounded right in the frame after we jumped, my raycast is still touching the ground (didn't have enough frames yet to distance ourselfs far enough from the ground with the jump) and sets the isGrounded state right after the jump frame and cancels is. A hack I use to make it playable is to disable the groundcheck raycast for a little while after jumping but that feels like a walk-around instead of a solution. Why doesn't this happen in your game?
@TheAsarath
@TheAsarath 6 ай бұрын
They are using the collider itself to check the isGrounded check and utilizing the bottom edge of the collider instead of doing a raycast. This video covers this: kzbin.info/www/bejne/mWTMdp9rdtyIfJo
@maksimnarrates1826
@maksimnarrates1826 Жыл бұрын
I do exactly the same, but controlling jump height doesn't work for me. I can jump as many times in the air as I want..
@neerkoli
@neerkoli 10 ай бұрын
On a slightly different note, which editor are you using? MonoDevelop?
@GameDevBeginner
@GameDevBeginner 10 ай бұрын
It's Visual Studio (Gruvbox theme)
@neerkoli
@neerkoli 10 ай бұрын
@@GameDevBeginner Thanks!
@Baron-rr4bt
@Baron-rr4bt Жыл бұрын
Please let me know? How to implement the trajectory route behind the object? Thanks. 😘
@GameDevBeginner
@GameDevBeginner Жыл бұрын
It's a line renderer, based on positions set in fixed update.
@Baron-rr4bt
@Baron-rr4bt Жыл бұрын
@@GameDevBeginner Tanks very much.😘😘😘😘
@MarbleAnimationsbred
@MarbleAnimationsbred Жыл бұрын
Is there a way to have an object jump without physics for 3D objects instead of 2D? And also thanks for this tutorial, it was really helpful
@GameDevBeginner
@GameDevBeginner Жыл бұрын
Yes. The same principle applies, where you have to make your own gravity, move the objet using its transform and do ground checks, just in 3D.
@MarvelAnchor
@MarvelAnchor Жыл бұрын
Hey Could U Maybe Give Me Code For A Working Jump 2d That U Cant Jump In Air Would Helps Loads Thanks
@GameDevBeginner
@GameDevBeginner Жыл бұрын
There's a ground check section in the article that this video is based on, if that helps: gamedevbeginner.com/how-to-jump-in-unity-with-or-without-physics/#ground_check
@damsen978
@damsen978 Жыл бұрын
13:41 Can't we just use a rigidbody for ground detection with Continous? While still using a character controller with scripted movement? I don't think there's a reason to not add an rb. The calculations aren't heavy for our computers, even with many players.
@GameDevBeginner
@GameDevBeginner Жыл бұрын
You could. There used to be a performance hit for moving 3D colliders around manually but I don't believe that's the case anymore, however it might still be thing with the 2D physics system. Generally though, the point of a rigidbody is to move a collider, so if you wanted manual movement with a rigidbody-based check then you could probably just use a kinematic rigidbody and the Move Position function to move it around. That way you'd get transform-style movement without mixing the two methods.
@ty-xq7bl
@ty-xq7bl Жыл бұрын
Can this deal with slopes?
@GameDevBeginner
@GameDevBeginner Жыл бұрын
I didn't consider slopes when I made it. I assume it would but you'd just need to change what you define as up. e.g. if the player is rotated, on the slope, do you want them to jump straight up? (Vector3.up) or up relative to them? (transform.up)
@rohitdas2169
@rohitdas2169 3 ай бұрын
m_rigidbody.gravityscale = gravityScale; Why that line sew me error
@GameDevBeginner
@GameDevBeginner 3 ай бұрын
Are you using a 3D Rigidbody? 2D Rigidbody has the gravity scale property, 3D doesn't.
@awesomewyvern
@awesomewyvern 10 ай бұрын
There is no explanation on how to do a ground check for unity based physics
@abg2487
@abg2487 Жыл бұрын
How to make Mario style jumping mechanism?
@GameDevBeginner
@GameDevBeginner Жыл бұрын
I believe the original Super Mario is a faster fall style jump. David Strachan did an analysis of it in his article here: www.davetech.co.uk/gamedevplatformer
@zucth8447
@zucth8447 9 ай бұрын
all the physic hump doesn't work at all. They seem too heavy to lift up no matter how many gravity I scale it
@elaicatubag8191
@elaicatubag8191 Жыл бұрын
wow I use the most unconventional way possible to make a player jump w/o physics 😅 I used lerping… lerp for the jump and until the player hits apex, then lerp for falling (gravity) is then triggered.. also, I used OnCollisionEnter to detect whether the player is grounded or not lmao
@romanslavinsky3722
@romanslavinsky3722 2 ай бұрын
I use almost the same method to jump to a specific height and yet my 3D capsule jumps approximately 1.3 units instead of 3: AddForce(transform.up * Mathf.Sqrt(2 * -Physics.gravity.y * height), ForceMode.VelocityChange) Cannot figure out why and how to solve it. So infuriating!!!!🤬🤯
@rhari7881
@rhari7881 2 ай бұрын
Hey! Saddly I am very much a begginer and cannot help you. Instead, I bring you yet a question. Why do we need to use squareroot to get the impulse force? I'm thinking about the basics of potencial gravitational energy and jump force in newtownian physics and I can only draw a resemblance with Force = mass * height * gravity. However, when I apply this formula, my jump is overwhelmingly heigher than I expected, and is only fixed by using the formular in the video: F = mass * sqrt(height * gravity * -2)! Would you mind to enlight me on the subject?
@ZombieChicken-X
@ZombieChicken-X Ай бұрын
I actually make my character jump by instead making the entire world move away from the player
@TexasBakedBlackBeans
@TexasBakedBlackBeans 3 ай бұрын
Hey, I know this is an old video, but I tried to follow your steps in order to make a 3D jump in Unity and it was going pretty well right up until the last part where I got an error that says: "There is no argument given that corresponds to the required formal parameter 'position' of 'Physics.ClosestPoint(Vector3, Collider, Vector3, Quaternion'
@GameDevBeginner
@GameDevBeginner 3 ай бұрын
In the video I used Physics2D.ClosestPoint for a 2D example, which takes a position and a collider, the 3D version, which I think you may be using, takes more parameters, the point to check from and then the collider, its position and rotation. Assuming that you have a collider reference, you could use Collider.ClosestPoint instead, and pass in just the position (see here: docs.unity3d.com/ScriptReference/Collider.ClosestPoint.html ) hope that helps.
@TexasBakedBlackBeans
@TexasBakedBlackBeans 3 ай бұрын
@@GameDevBeginner Hey, thanks for the quick reply, but I'm now having a similar problem with Physics.OverlapBox as it works much differently than Physics2D.OverlapBox
@TexasBakedBlackBeans
@TexasBakedBlackBeans 3 ай бұрын
​@@GameDevBeginner Hey, thanks for the quick reply, but I'm having trouble with the ground check as Physics.OverlapBox uses different parameters than Physics2D.OverlapBox and I don't know any other way to do it.
5 tips for better platformer controls
5:22
The Shaggy Dev
Рет қаралды 186 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 681 М.
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,4 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 4,8 МЛН
Watermelon Cat?! 🙀 #cat #cute #kitten
00:56
Stocat
Рет қаралды 22 МЛН
Super gymnastics 😍🫣
00:15
Lexa_Merin
Рет қаралды 83 МЛН
I Made A Physics Engine
6:59
Zyger
Рет қаралды 140 М.
Unity Movement [RigidBody vs Translate]
9:00
Press Start
Рет қаралды 282 М.
Making a Character Jump (Unity Tutorial)
7:36
Ketra Games
Рет қаралды 75 М.
Improve your Platformer’s Jump (and Wall Jump) | Unity
8:12
Better Jumping in Unity With Four Lines of Code
12:47
Board To Bits Games
Рет қаралды 817 М.
Coyote Time & Jump Buffering In Unity
3:48
bendux
Рет қаралды 73 М.
Math for Game Programmers: Building a Better Jump
25:43
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,4 МЛН