How to jump in Unity (with or without physics)

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น • 66

  • @MyPing0
    @MyPing0 2 ปีที่แล้ว +43

    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!

  • @victrozzz
    @victrozzz 2 ปีที่แล้ว +9

    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

  • @THExRISER
    @THExRISER 2 ปีที่แล้ว +4

    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.

  • @b0b0_
    @b0b0_ ปีที่แล้ว +2

    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 🙏🏾🙏🏾

  • @muhammadzubairirshad6724
    @muhammadzubairirshad6724 ปีที่แล้ว +1

    The way of Teach is just amazing

  • @ligofleyens9131
    @ligofleyens9131 2 ปีที่แล้ว +5

    Personally I also like to add the coyote time variable to give those extra millis to trigger when making big jumps from platforms.

  • @attilagal6459
    @attilagal6459 2 ปีที่แล้ว +1

    Uprising Brackeys 2.
    Keep it up!

  • @ricardomachado1169
    @ricardomachado1169 ปีที่แล้ว +1

    Amazing tutorial, thanks so much!

  • @kiel5390
    @kiel5390 2 ปีที่แล้ว

    Always quality videos!

  • @nava.a_rts
    @nava.a_rts ปีที่แล้ว

    this is amazing i love u man

  • @KindoSaur
    @KindoSaur 6 หลายเดือนก่อน

    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

    • @GameDevBeginner
      @GameDevBeginner  5 หลายเดือนก่อน

      Assuming that the only issue is that the object is moved past the ground before it can detect it, then you'll want to try a lookahead raycast for the movement that's going to take place in the next frame and then move the object back if it detects a surface. It sounds like you're already doing something like this so if you don't mind sharing your code with me at support@gamedevbeginner.com I can take a look and try to help.

  • @rtfranco
    @rtfranco ปีที่แล้ว +1

    Nice 14:00, but what about slopes (45°, 60°, etc)? How to calculate this offset height in this case?

  • @MarekNijaki
    @MarekNijaki 2 ปีที่แล้ว

    Awesome video

  • @sparx7747
    @sparx7747 3 หลายเดือนก่อน

    Hello friends, I am facing a problem, Is that player is constantly jumping a bit up ( In Unity2D ), I was following this article and video. However when I increase the "Offset" to 1 On the GroundCheck Script the player does not jump by itself but a gap is created between the player and the ground.....
    I'm not using physics system my approach is manual gravity.

  • @TackleProd
    @TackleProd ปีที่แล้ว

    Great video :)

  • @kingofspades9720
    @kingofspades9720 5 หลายเดือนก่อน

    Great video! I had a question, how can I make the shortest jump even shorter? because as it stands the smallest jump I can make is generally close to half the size of the maximum jump no matter how little I press space, but for example in games like Hollow Knight, it feels like I have a lot of precise control over how long I jump, including if I want to do a really short jump.

  • @2deep215
    @2deep215 2 ปีที่แล้ว

    Finlly thanks dude

  • @maksimnarrates1826
    @maksimnarrates1826 ปีที่แล้ว +1

    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..

  • @V1b1ngC0w
    @V1b1ngC0w ปีที่แล้ว +1

    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

  • @ZombieChicken-X
    @ZombieChicken-X 7 หลายเดือนก่อน +4

    I actually make my character jump by instead making the entire world move away from the player

    • @bovineox1111
      @bovineox1111 2 หลายเดือนก่อน

      That sounds insane!

    • @ZombieChicken-X
      @ZombieChicken-X 2 หลายเดือนก่อน

      @@bovineox1111 XD I was just kidding

  • @samooniyaksaman9509
    @samooniyaksaman9509 ปีที่แล้ว

    What is the final solution for slope question?

  • @cs91635
    @cs91635 ปีที่แล้ว

    Can you do the jump height cancel on the jump with out physics?

  • @dhantheman2447
    @dhantheman2447 3 หลายเดือนก่อน

    How do u actually calculate the "buttonpresswindow"?

    • @GameDevBeginner
      @GameDevBeginner  3 หลายเดือนก่อน

      If I remember right it's not a calculation, it's a just value that you set manually and can adjust.

    • @dhantheman2447
      @dhantheman2447 3 หลายเดือนก่อน

      @@GameDevBeginner alright thanks man👍

  • @ΙΜΜυΝΙΤΥ
    @ΙΜΜυΝΙΤΥ ปีที่แล้ว +1

    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

  • @ahmed_nady_20
    @ahmed_nady_20 2 หลายเดือนก่อน

    how to make double jump in this code wihtout physics

  • @Baron-rr4bt
    @Baron-rr4bt 2 ปีที่แล้ว

    Please let me know? How to implement the trajectory route behind the object? Thanks. 😘

    • @GameDevBeginner
      @GameDevBeginner  2 ปีที่แล้ว

      It's a line renderer, based on positions set in fixed update.

    • @Baron-rr4bt
      @Baron-rr4bt 2 ปีที่แล้ว

      @@GameDevBeginner Tanks very much.😘😘😘😘

  • @acedia4454
    @acedia4454 ปีที่แล้ว

    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 ปีที่แล้ว

      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: th-cam.com/video/c3iEl5AwUF8/w-d-xo.html

  • @rohitdas2169
    @rohitdas2169 9 หลายเดือนก่อน

    m_rigidbody.gravityscale = gravityScale; Why that line sew me error

    • @GameDevBeginner
      @GameDevBeginner  9 หลายเดือนก่อน

      Are you using a 3D Rigidbody? 2D Rigidbody has the gravity scale property, 3D doesn't.

  • @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/

  • @neerkoli
    @neerkoli ปีที่แล้ว

    On a slightly different note, which editor are you using? MonoDevelop?

    • @GameDevBeginner
      @GameDevBeginner  ปีที่แล้ว

      It's Visual Studio (Gruvbox theme)

    • @neerkoli
      @neerkoli ปีที่แล้ว

      @@GameDevBeginner Thanks!

  • @romanslavinsky3722
    @romanslavinsky3722 8 หลายเดือนก่อน

    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!!!!🤬🤯

    • @E-Rhari
      @E-Rhari 8 หลายเดือนก่อน

      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?

  • @awesomewyvern
    @awesomewyvern ปีที่แล้ว

    There is no explanation on how to do a ground check for unity based physics

  • @PonderingPebble
    @PonderingPebble ปีที่แล้ว

    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

  • @Zucth
    @Zucth ปีที่แล้ว

    all the physic hump doesn't work at all. They seem too heavy to lift up no matter how many gravity I scale it

  • @Marble-Animations
    @Marble-Animations ปีที่แล้ว

    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.

  • @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)

  • @abg2487
    @abg2487 2 ปีที่แล้ว

    How to make Mario style jumping mechanism?

    • @GameDevBeginner
      @GameDevBeginner  2 ปีที่แล้ว

      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

  • @TexasBakedBlackBeans
    @TexasBakedBlackBeans 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน +1

      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 9 หลายเดือนก่อน

      @@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 9 หลายเดือนก่อน

      ​@@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.