Тёмный

Making a Jump You Can Actually Use In Godot 

Pefeper
Подписаться 6 тыс.
Просмотров 78 тыс.
50% 1

Manually tweaking your character's jump velocity and gravity in Godot is hardly an effective way to make a jump. It's imprecise, and above all, tedious to make something that actually feels good to play. In this video, you'll learn how to make a jump you can actually use in your game, by breaking it down into real parameters you already know how to use (like height and time), then calculating jump velocity and gravity at runtime.
Link to the GDC talk: • Math for Game Programm...
Link to the GitHub code: gist.github.com/sjvnnings/5f0...

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

 

10 июл 2021

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 207   
@Pefeper
@Pefeper 6 месяцев назад
I have had several people over the last 2.5 years ask for a copy of the 200 pixel ruler background from the platformer example. So, I've uploaded a copy anyone can download here (consider it CC0): drive.google.com/file/d/1iJ2LDDIQTHzo6HJT_YGEeLugkr-1_w0Q/view?usp=sharing
@catotonic1881
@catotonic1881 5 месяцев назад
hi, I have a question, could you modify this code so that you can control the jump height by pressing and holding the jump button? its so that you could make short jumps with tapping the space bar.
@Pefeper
@Pefeper 5 месяцев назад
@@catotonic1881 You need to apply more gravity on the player when they release the jump button, which will make them fall faster. You could parameterize this in terms of the minimum jump height and the time it takes to reach this minimum jump (both values must be lower than the regular jump height and jump time respectively). You can then calculate early_release_gravity = (min_jump_height - jump_velocity * min_jump_time) / (min_jump_time * min_jump_time)early_release_gravity : float = (min_jump_height - jump_velocity * min_jump_time) / (min_jump_time * min_jump_time) Then, in get_gravity, do something like this: func get_gravity() -> float: if velocity.y > 0.0: return fall_gravity if Input.is_action_pressed("jump"): return jump_gravity return early_release_gravity That should roughly do the trick. If the player taps the jump button for a single frame, they will do the min jump in the min time. If they hold the jump button for the entire jump, they will do the full jump. If they release the button sometime between those two timeframes, their character will start to fall at some height between the min and max. Hope that helps!
@catotonic1881
@catotonic1881 5 месяцев назад
@@Pefeper found a different solution, that works well. ass of now I would like to know how to add a coyote time effect as well as having the ability to activate the jump function 0.1 or 0.2 seconds before the character hits the ground. sorry if I'm asking too much I'm new to the whole game dev thing. thank you though, you vids are really helpful.
@Perndoe
@Perndoe 5 месяцев назад
Hello, I have a question. The difference between global position of the player when standing still and at peak of the jump does not equal to the jump height I set (it is off around 8 pixels). How to fix this
@Pefeper
@Pefeper 5 месяцев назад
@@Perndoe it's hard to say exactly why this would be happening without seeing your setup, but Godot 4 changes the implementation of character body quite a bit. My guess is that it's an issue converting this code to Godot 4. I'll try to upload an updated version of this script later today on the github gist
@MasterAlbert
@MasterAlbert 3 года назад
bruh this is a top quality tutorial
@Shubhyduby
@Shubhyduby 3 года назад
Agreed.
@Joyblaster
@Joyblaster 11 месяцев назад
Master albert , your videos are also really good
@cherryblossoms5970
@cherryblossoms5970 9 месяцев назад
Yes it is 😃
@ShanjeiGuna
@ShanjeiGuna 3 года назад
I just watched that GDC presentation and was left a bit puzzled coz I'm dull. But you, with this straightforward guide just made my life much easier. Thank you so much for this!
@pianoatthirty
@pianoatthirty 2 года назад
Not because you’re “dull”, it’s because their intention (and most public speeches for that matter) have the unconscious hidden agenda to “look smart” in front of others, thereby making something that could be explained simply explained in a convoluted manner. This video, on the other hand, is actually about teaching you something.
@junba1810
@junba1810 8 месяцев назад
@@pianoatthirty I disagree with you here. If you saw the GDC talk it was very obvious that the speaker had a very limited time allowed to talk. He talked really fast and barely managed to finish before the other guy took his place. Maybe he could have explained things in more depths if there weren't any time restraints.
@jlewis4441
@jlewis4441 3 месяца назад
​@@pianoatthirty Or maybe, and hear me out, it's because the point of the talk was to be a mathematical break down of the subject in as much detail as possible? Don't get me wrong, I'm sure there are plenty of public speakers who are just trying to look like they're smarter than everyone else, but I've seen the talk. It's a good talk. The math is thorough and it's explained well enough, though as the other comment mentioned you can see the influence of time crunch impact the teaching. Both that talk and this video are about teaching the audience, one being the base concept of the subject and the other being the actual real world application respectively.
@vedarthjoshi2166
@vedarthjoshi2166 9 месяцев назад
if anyone is looking starting point for this in godot 4 extends CharacterBody2D @export var speed = 400 func _physics_process(delta): velocity.x = get_input_velocity() * speed if Input.is_action_just_pressed("ui_up") and is_on_floor(): jump() move_and_slide() func jump(): pass func get_input_velocity() -> float: var horizontal := 0.0 if Input.is_action_pressed("ui_left"): horizontal -= 1.0 if Input.is_action_pressed("ui_right"): horizontal += 1.0 return horizontal
@rollinsushi3502
@rollinsushi3502 8 месяцев назад
thank you so much, i couldn't get rid of an error regarding the velocity. Now it works perfectly
@LucaHofmann
@LucaHofmann Месяц назад
Thank you for the video! Two ideas to improve the code: 1) Make your jump_height value negative (e.g. -100) and remove the -1 multiplications from your calculations. 2) Rename jump_time_to_peak to jump_seconds_to_peak and jump_time_to_descent to jump_seconds_to_descent. Why? 1) Don't add the circumstance that in Godot Y -1 is UP to your calculations if you do not need to. Someone who edits the jump_height is most likely aware that -1 points up. No need to hide that fact. 2) It is nice to know the unit of the time by looking at the variable name. Someone who edits the variable does not have to guess.
@ThalesCardris
@ThalesCardris 12 дней назад
Although I find this constructive, I think the first one is a matter of preference. I would much rather see positive values in my exports than having to add that - all the time.
@benjaminnewington9099
@benjaminnewington9099 Год назад
Awesome video! To expand upon this, here's how you add a variable jump height. Add an export var called _variable_jump_height_ , and then an onready var called _variable_jump_gravity_ , which is calculated as: (jump_velocity * jump_velocity) / (2 * variable_jump_height) - multiply by -1 if you are working in 3D Then just modify the _get_gravity()_ function to return _variable_jump_gravity_ instead of _jump_gravity_ if the player is holding the up button :)
@Silvanus92
@Silvanus92 7 месяцев назад
Thanks!!! ♥
@noxy539
@noxy539 7 месяцев назад
so I know that this is 8 months late but how do you actually go about checking if the player is holding the button?
@woohoo730
@woohoo730 7 месяцев назад
@@noxy539 you could just use if statements like this if Input.is_action_pressed("jump"): # make sure that its NOT is_action_just_pressed() return jump_gravity elif Input.is_action_just_released("jump"): return variable_jump_gravity return variable_jump_gravity
@Z-713
@Z-713 7 месяцев назад
@@noxy539 not sure if you figured it out yet, but instead of checking if they're holding the jump button we should just check if they release the jump button. So we can say "if Input.is_action_just_released():" then run our code. Keep in mind that we need to make sure the player can't spam the jump button to reset their gravity (since every time we release it will return true for the if statement). This means we should keep track of if the player is jumping. When Input.is_action_just_pressed() we can set "is_jumping" (name it whatever) to True. Then when Input.is_action_just_released() we can set that same variable to False. I am a noob but this is how I did it. Hope this helps!
@noxy539
@noxy539 6 месяцев назад
@@Z-713 yeah I figured it out after, I just decided to divide the player velocity by 1.5 if they let go and it gave me a pretfy smooth jump
@junba1810
@junba1810 9 месяцев назад
Wow, this must be one of the most professional tutorials I've ever seen. Straight to the point with good visual explanations and following black box principles for users not looking to get too much into it. Thanks for this video! I am definitely saving it for later use :)
@wellhellotherekyle
@wellhellotherekyle 2 года назад
Duuuude THANK YOU. I look forward to more videos from you, love your style of teaching and the presentation. Good job!
@HybridLizard_com
@HybridLizard_com 2 года назад
Great video! Quick, straight to the point and presenting nice, controllable approach for implementing the feature.
@hyperventalated
@hyperventalated Год назад
Implemented this into my platformer and it worked like a charm, feels really nice! Also the tip about the descent being faster than the ascent is not something I've particularly noticed before, that's great! Thank you for the help!
@cody_code
@cody_code 4 месяца назад
I was specifically looking for a good example on implementing all the stuff I tried to learn in that GDC talk, and here it is, in 3 1/2 minutes. You're the best!
@lucksterduck
@lucksterduck 2 года назад
Easiest sub of my life. Such a clear and concise tutorial. Thank you sir!
@panampace
@panampace Год назад
This is a perfect tutorial. I watched that gdc talk before, understood the math, but was completely clueless about where to implement it in my code.
@nomeimporta6465
@nomeimporta6465 3 года назад
What a great tutorial and excellent quality, new subscriber!
@eskimopie910
@eskimopie910 5 месяцев назад
Absolutely killer video. Exactly what I was looking for, short and to the point too. Great resource, thanks!!!
@spaghettiman512
@spaghettiman512 2 года назад
The saviour of time, thanks a lot for simplifying the original talk! I don't understand the full thing yet but I'll try to.
@compasscrafting1147
@compasscrafting1147 Год назад
Stellar. Appreciate the link to the GDQuest explanation of the math going into it as well.
@breffish
@breffish 2 года назад
one of the best tutorials i didn't know i needed - thanks a bunch for this!
@MrEliptik
@MrEliptik 3 года назад
Nicely explained! This is really great.
@metenke
@metenke 7 месяцев назад
Stellar video my guy. I was wondering how to do this myself, so thanks
@CCV334
@CCV334 3 года назад
Makes way more sense to work with numbers this way. You sir have earned a fresh subscriber.
@oJo_4412
@oJo_4412 Год назад
This was an amazing tutorial and it got to the point quickly :)
@alvarooo4715
@alvarooo4715 3 года назад
I have been looking for a good example on something like this to apply to a 3d game, Thanks a ton!
@jasenlakic5033
@jasenlakic5033 Год назад
Great tutorial, short and well done
@azralan618
@azralan618 7 месяцев назад
I might be a little late but thank you so much for this. I had this idea for a 2D parkour platformer and there are a lot of different jump types. This makes tuning them way easier than I had feared.
@OrgiT
@OrgiT 2 года назад
The best Godot tutorial I've ever watched! You diserve a sub for that one!
@ohmygigglez4464
@ohmygigglez4464 2 года назад
Great tutorial! Super easy to understand!!
@olson5000
@olson5000 5 месяцев назад
This was wonderfully easy to follow for a newbie - THANK YOU!!
@scubedibap
@scubedibap 3 месяца назад
Great work, this helps so much!
@jugibur2117
@jugibur2117 Год назад
Just what I was looking for, thanks for sharing!
@BrandonScott-zn9vl
@BrandonScott-zn9vl 2 месяца назад
For those doing this in 3D and your jump height is inconsistent: Make sure this line: [return jump_gravity if velocity.y < 0 else fall_gravity] Is now: [return jump_gravity if velocity.y > 0 else fall_gravity] Also just generally make sure you are applying negative values to velocity.y for gravity...not positive. One wrong sign will mess up the whole thing.
@davidbolt9370
@davidbolt9370 Год назад
this is so much better then what i had before thank you
@Nitbandier
@Nitbandier 3 года назад
Omg its so good Liked and subed!
@andrewmettler2228
@andrewmettler2228 4 месяца назад
This is great stuff. I'm coming from Unity and had already learned how to do something similar in C# and I was hoping someone had done it in GDScript as well. Thanks!
@findot777
@findot777 Год назад
10/10 would recommend this went in flawlessly into my already very complex jump code with variable jump coyote time and jump buffer amazing
@RenderingUser
@RenderingUser Год назад
Without a doubt the most useful platformer code for godot I'm adding this to my platformer templates
@BluenatorT800
@BluenatorT800 2 года назад
Your channel is gold, thanks for share good info with funny videos
@evprkr3914
@evprkr3914 11 месяцев назад
This is great. The only thing I'd add is variable jump height, aka letting go of the jump button early makes your jump shorter.
@josephxavier8636
@josephxavier8636 3 года назад
Awesome tutorial, thanks!!
@Pixelaze
@Pixelaze 2 года назад
Brilliant!! Thanks for this.
@Molul_
@Molul_ 5 месяцев назад
Amazing lesson. Thank you very much.
@chaoscifer1483
@chaoscifer1483 Год назад
So neat! Thank you!
@nakajimakuro
@nakajimakuro 3 года назад
Quick and easy to understand
@darkstrife1
@darkstrife1 3 года назад
nice work... just earned yourself a like and sub ✌🏾
@imogiagames
@imogiagames 4 месяца назад
Thank you so much !😁
@BioniXdu25
@BioniXdu25 3 года назад
Thanks a lot !
@johnnobon
@johnnobon Месяц назад
I think this is the best video for getting the jump right, with it allowing you to control both the height and the time to reach the height. I think using the default gravity often slows down the jump too much as you reach the peak. One thing this doesn't do is allow you to "short" the jump by just tapping and letting go, or do the jump to full height by holding the button. I got this added in 3D using the following line under _physics_process(delta), and I think it would work in 2D if you reverse the signs: if Input.is_action_pressed ("jump") == false && velocity.y > 0: velocity.y -= 1 You can replace the velocity.y -=1 with whatever deceleration formula you want. You can also add a terminal velocity for your character by adding the following under your _physics process: velocity.y = clamp(velocity.y, -100, 100) replacing the 100s with whatever variables you want to use as the min and max velocity. This makes it so your character's fall speed will not increase indefinitely and eventually become constant. Otherwise you may find your character falling way too fast from big heights.
@BrannoDev
@BrannoDev Год назад
Easy to implement and easy to understand.
@aussenseitermagazin
@aussenseitermagazin 3 года назад
Beautiful
@mattdavis135
@mattdavis135 Год назад
This is literally the perfect tutorial.
@depressito
@depressito 4 месяца назад
omg I was able to implement this with too many if else statements because I don't have the math knowledge.. this taught me that I need to learn math because there will be moments in which I can simplify the code too much by learning math
@mr.shplorb662
@mr.shplorb662 6 месяцев назад
I've been using this in all of my godot projects, and absolutely love it! Just wondering if you have a version that could be used in unity, as using other methods just don't quite fit what i am looking for, and this fits my needs perfectly. Again, phenomenal work, it's made my godot games feel so much better
@Lel37178
@Lel37178 3 месяца назад
just figured this out recently but in case anyone has this issue where the character teleports to the jump height rather than jumping normally, you just change: velocity.y = get_gravity() * delta to velocity.y += get_gravity() * delta this worked for me in a 3D game, idk if it does the same on 2D (itll maybe turn the jump into a really high jump so you might need to tweak the numbers a bit-) great video btw it helped me a lot!
@4per8
@4per8 2 месяца назад
i think thats because your supposed to set the velocity to jump_velocity and use get_gravity for getting the gravity
@Lel37178
@Lel37178 2 месяца назад
@@4per8 probably yeah. didnt have time to check it out but i agree that might has to do with it (im still quite starting to learn gdscript lol)
@CubeOrSomething
@CubeOrSomething 20 дней назад
Finally, a game developer who doesn't yell.
@oldman222
@oldman222 Год назад
Thank you
@pyramiddev5715
@pyramiddev5715 2 года назад
the tutorial is better than other..
@itsME-dc4vm
@itsME-dc4vm 3 года назад
niceeee thankssss ;D
@Drachenbauer
@Drachenbauer 5 месяцев назад
I used this in an automatic racing-ki like used in the races of the duck-life-series (that detects terrain and automaticly uses the matching movement-skill). So i got a nice little jump for transition from climbing up a wall to reach it's top and continue running along the horizontal surface up there
@salarycat
@salarycat 3 года назад
Nice idea! I wonder if it makes sense to have a "hang-time" control as well, to define the curvature of the jump.
@Pefeper
@Pefeper 3 года назад
Do you mean like stalling in the air for a little bit after you reach the peak? You could probably do a check if the player's vertical velocity is close to 0 (which would be the peak) in get_gravity and then return 0 to keep the player steady in the air. Maybe use a timer to control how long they're up there for? I have no idea how this would actually feel to play haha, but the nice thing about this code is that it's flexible enough to experiment with
@salarycat
@salarycat 3 года назад
@@Pefeper Yeah like stalling but I guess it should be smooth, not like hitting a wall. Maybe using variable gravity force? But in the end it would be nice to have intuitive controls like ascend time, hang time, descend time. I've also been experimenting with it, I'll try it out.
@Pefeper
@Pefeper 3 года назад
@@salarycat Oh, OK, I see what you mean I think. Adding an additional hang_time_gravity variable would probably be the way to go, and returning it as the player's velocity approaches 0 in get_gravity(). You could *probably* calculate it in a similar way to the variables we do here, by defining a height it triggers at and the time it takes for the player to reach the peak and start falling again. The equation should be the same as the other gravity variables.
@GabrielMatusevich
@GabrielMatusevich 3 года назад
gem tip
@Thouova
@Thouova 6 месяцев назад
i want to frame this video and put it on my wall. thank you for making it :)
@danbam9018
@danbam9018 8 месяцев назад
how can I jump a certain height depending of how much time I have the jump button pressed?
@gofastutos
@gofastutos 2 года назад
Fast and clear tutorial, like I prefer ans like I do 👍
@crispodispo
@crispodispo 2 года назад
I'm your 1000th subscriber, this video was really well explained and straight to the point, keep it up! Also I'm just curious, in Mario you can change the height you jump by holding the jump button for how high you want to jump, I'm just wondering how I would do this?
@Pefeper
@Pefeper 2 года назад
Thanks a ton for the sub, I'm glad you liked the video! As for the Mario jump, you'll need to apply some kind of downwards force on the player when they release the jump button to make them fall faster. In the get_gravity function, you could check if the jump button has been released, and if velocity.y < 0 (player is moving up), return fall gravity * 2 (or some other multiplier)
@crispodispo
@crispodispo 2 года назад
@@Pefeper woah didn't expect you to answer so soon, thanks btw :) Btw will this work I have a constant gravity variable?
@Pefeper
@Pefeper 2 года назад
@@crispodispo You should only apply the gravity multiplier when the player is still moving upwards (velocity.y < 0). That way, the player will lose their upwards momentum more quickly. When they start falling downwards though, you just apply gravity like you would normally. The player won't feel anything besides the usually gravity amount when they fall. If you aren't using a function like get_gravity(), I would recommend implementing one, even if you have constant gravity. It makes doing things like gravity multipliers a lot easier! Hopefully that answered your question!
@crispodispo
@crispodispo 2 года назад
@@Pefeper ok I'll try this, thanks
@catotonic1881
@catotonic1881 5 месяцев назад
I tried to copy what you did here, but I get errors telling me something like "floats make no sense" so I replaced them with "1.0" on the export var and changes the "'floats" on the on ready vars with the move_speed and it worked. my question is, what could be the problem with my first code for it to not work, and was the solution I came up with correct, in terms of did my solution result in the same outcome as your tutorial, cause I cant really tell if I did it right, I mean my character was moving but I can't tell if its the same as yours.
@martlepanen771
@martlepanen771 3 года назад
What are your thoughts on horizontal movement during a jump? I find this really hard to nail down and make feel right as well. Do you have any tips on getting it right?
@Pefeper
@Pefeper 3 года назад
It definitely depends a lot from game to game. I think it's good to allow the player some degree of mid air movement, but not so much that they can quickly cancel a jump. What I usually do is treat mid air horizontal velocity change as interpolation from the current velocity to the player's desired velocity. Godot has a built in lerp function that's helpful for this. You would do something like current_hvel.lerp(input_hvel, arbitrary_fraction × delta). Hvel stands for Horizontal velocity. That arbitrary fraction will make the jump feel weightier at lower values. 0 will make it impossible to move in the air. With this method you will infinitely approach the goal velocity, but technically never actually reach it. To solve that, just clamp it at the end to the desired velocity if the difference between the current and desired is small enough. Hopefully I made some sense haha. It's a bit late here, but I wanted to respond as soon as I could.
@mrmisterson43
@mrmisterson43 4 месяца назад
For some reason when I use @export in godot 4, it makes the gravity extremely high to the point I never see the player even if I have a camera following it. When I get rid of the @export and put the same numbers in, it works fine. Is there a reason this is happening?
@Purpbatboi
@Purpbatboi Год назад
this is nice but the jump height inst controllable tried implementing it but it doesn't look as smooth
@JKd3vLD
@JKd3vLD 2 года назад
Man, where can I find that ruler (measure tape) asset you're using in this video? :0
@PaladinNoGames
@PaladinNoGames 3 месяца назад
|||ERROR|||ERROR|||On Godot 4 were it doesnt seem to work, i know the error must be on me, but i have the issue that the player doesn't jump up rather it getdsteleported up to the peak and then falls with the fall gravity.
@switch3
@switch3 2 года назад
I understand that move_and_slide() already taken delta into account. But I'm always stumped as to why the Y component of the velocity (the gravity portion) needs to be multiplied by delta?
@Pefeper
@Pefeper 2 года назад
Good question! It's because the effect of gravity accumulates over time. Think about when an object falls. The longer it falls, the faster it gets. Gravity doesn't move us downwards at a constant rate, but instead it constantly subtracts from our upwards velocity. In our gravity model, we suppose that our gravity variables are represented as units per second. So, every second, our upwards velocity should be lowered by jump_gravity or fall_gravity units. We can do that by just adding gravity * delta to velocity.y. Hopefully that helps!
@assaadeloualji859
@assaadeloualji859 Год назад
Hi! For some reason when I modify the jump_time_to_peak and jump_time_to_descent, the jump_height is no longer respected. The jump's height is no longer equal to the one I set. Any help would be greatly appreciated. Thank you.
@roughdragonfly
@roughdragonfly 3 месяца назад
Same!! I copied and pasted the code, too. Changing the times changes the jump height
@monstereugene
@monstereugene 2 года назад
hmm but is there a easy way to run a variable height?
@ShadowPianoProductions
@ShadowPianoProductions 7 месяцев назад
Not all heroes wear capes
@greocan9910
@greocan9910 4 месяца назад
One thing I'm struggling with design wise is wither I should have different gravities for different jumps. I have 2 jumps a normal jump and a backflip jump like in Mario 64. Should they have different gravities? Wouldn't that make the player fall differently depending on which jump they used? Is that good or bad?
@Pefeper
@Pefeper 4 месяца назад
Players will definitely be able to tell that they're falling at different speeds with different jumps. In my experience with platformers, every type of jump has the same gravity applied to it, and that tends to feel natural. But, it might be worth experimenting with variable gravities! If you think it feels good, don't feel a need to change it out of convention.
@trip7141
@trip7141 2 года назад
Something kind of interesting, I was using similar but different equations for this same effect from Game Endeavor's video (Gravity is derived from the same equation): max_jump_velocity = -sqrt(2 * gravity * max_jump_height) min_jump_velocity = -sqrt(2 * gravity * min_jump_height) But I replaced them with the equations from this video and have much finer control over my jump height now based on how long I hold the button. I'm not quite sure WHY but it seems like something worth noting.
@Gabu_
@Gabu_ 2 года назад
Also of note is that sqrt is an expensive operation, when compared to multiplication. Certainly won't make a difference for one player node, but suppose you tried to control one thousand objects in this way - then it'd start to become significant.
@LjstarZero
@LjstarZero Год назад
This is amazing and exactly what I needed for my project! I had enough trying to guess jump height by typing some random values and trying to wing it lol I do have one question tho if you don't mind, I'm trying to make my character fall earlier when i release the button in mid-air, have any tips?
@Pefeper
@Pefeper Год назад
I'm glad you liked the video! For the early fall, you need to apply a more intense gravity when the players velocity is still upwards, but the jump button is no longer being pressed. I don't know a clean way to do this at the moment, but maybe just apply jump velocity * 2 when the jump button is released? (Make sure you only use fall gravity when the player is falling downwards though)
@LjstarZero
@LjstarZero Год назад
@@Pefeper Aaah, I completely forgot to respond to this, my apologies! Thanks a lot for the tip! I ended up going with something similar and it works like charm, thanks again!
@AleczanderSmith
@AleczanderSmith 8 месяцев назад
great video but 1 (maybe 2) issues: line 22 gets an error at runtime 'Velocity redefined (original in native class `characterbody2d`)' and any way I have tried to fix that issue results in movement being impossible, I am not sure what I am misunderstanding.
@Pefeper
@Pefeper 8 месяцев назад
Godot 4 added a "velocity" variable to the CharacterBody class, so you can just remove it from your script
@Hyperboid
@Hyperboid 8 месяцев назад
I had to copy the final script and 4-ify _that_. A diff revealed that my only mistake I made was forgetting to multiply gravity by deltatime...
@drbuni
@drbuni Год назад
I always get a "Division By Zero in operator '%'." when I try your code. A shame, but this seems really cool, either way.
@tonyramirez593
@tonyramirez593 Год назад
This is a great tutorial, thank you for making and uploading. I was just wondering how the down velocity function might change if there is a double jump in the game (if it would need to change at all)? My initial thought was since the jump height is being increased through a double jump, the down velocity calculation might be too fast. Could totally be wrong but wanted to know your thoughts
@Pefeper
@Pefeper Год назад
If you're talking about the gravity function, I don't think you would need to change it. All it does is check if the player is moving up or down, the height shouldn't matter
@tonyramirez593
@tonyramirez593 Год назад
@@Pefeper I meant the onready var fall_gravity(). Since it's using time to descent, I thought the time would need to change if the person double jumps (e.g. double time since the jump height doubled).
@Pefeper
@Pefeper Год назад
@@tonyramirez593 When you jump a second time, just call the jump function again so it sets the player's y velocity back to jump velocity. You shouldn't need to do anything to gravity, that should remain the same regardless of how many times you jump
@Goofykoopaboi
@Goofykoopaboi 10 месяцев назад
This was a great tutorial, but I'm having a weird thing happen. For some reason as the error states: "Too many arguments for "move_and_slide()" call. Expected at most 0 but received 2.", if anyone knows how to fix this, help me out please.
@Pefeper
@Pefeper 10 месяцев назад
Godot 4 implements move_and_slide differently than Godot 3 (which is what this tutorial was made for). Now you need to modify the Character Body's velocity variable (instead of creating your own velocity variable in the script). Then, call move_and_slide with no arguments
@Goofykoopaboi
@Goofykoopaboi 10 месяцев назад
@@Pefeper Alright, how do I modify the velocity variable and all that to get it correctly, unless it's really simple and I'm just dumb mindedly clueless rn lol.
@georgeml-o_o
@georgeml-o_o Год назад
The problem I see with time based jumps is when there is a momentaneous low frame rate, the jump can get higher. How can I solve this?
@quanwashington1115
@quanwashington1115 Год назад
Are you putting the logic that moves the character in _physics_process?
@RedEyedJedi
@RedEyedJedi 6 месяцев назад
Your get_input_velocity() function returns 1.0 for left. Shouldn't that be -1.0?
@vanquist6498
@vanquist6498 2 года назад
Great tutorial! one problem though, when I drop from a platform without jumping, I fall at a pretty fast rate as compared to jumping off the platform
@DFM605
@DFM605 Год назад
You should add a "velocity = move and ______(......)" instead of just "move and _____(......)" it self
@DFM605
@DFM605 Год назад
Tell me if you found this helpfull
@personal_acc
@personal_acc 7 месяцев назад
It gives me an error saying that it cannot convert a bool into a vector2@@DFM605
@harutokaito5061
@harutokaito5061 7 месяцев назад
A little off-topic but how did you get that ruler into your demo scene? I'd love to have that for prototyping!
@Pefeper
@Pefeper 7 месяцев назад
I made it myself in Aseprite! You're not the first person to have asked for it, I'll upload it to Google drive and share the link later
@chungosbruhthe1st
@chungosbruhthe1st 2 года назад
this is great. Just one question, I've tried alot of different ways but cant seem to get coyote time right with this code. Any ideas / help? cheers
@Pefeper
@Pefeper 2 года назад
I would try starting a timer as soon as the player is no longer on the floor. Then just let the player continue to jump until the timer times out
@storyMad
@storyMad 2 года назад
Thanks for the video. Any chance you'd share your whole project on Github? I replicated just the Player jumping code and my character flies off the screen. Would love to see what I'm doing wrong! :p
@Pefeper
@Pefeper 2 года назад
The player setup is just a KinematicBody with a capsule collider on it and no other settings altered. I would've put the whole project on GitHub, but most of it is just graphics and the single script. I figured a gist would suffice. If you're sure you got it set up correctly, take some screenshots of the code and your player and put them in a comment on the GitHub gist and I'll try to help how I can!
@maybeanonymous6846
@maybeanonymous6846 2 года назад
how do i make it so that if i was on floor recently i can jump
@Pefeper
@Pefeper 2 года назад
Do you mean Coyote time, where you can jump for a brief period of time after falling off a ledge? If so, just make a timer, start it when the player suddenly stops being on the floor but didn't jump, and let the player jump if they press the button before the timer runs out.
@dailymuseum
@dailymuseum 2 года назад
Does it take the running speed into the equation as well? Like in Mario, if Mario runs faster, he can jump higher
@MeBadDev
@MeBadDev Год назад
No, it doesn't, but that should be pretty easy to implement
@JuhoSprite
@JuhoSprite 4 дня назад
Anyone know why time to peak somehow changes the jumpheight? is this supposed to happen??? I just want the jump height parameter to be the single thing determining the height, and jump time to peak only changing the time and not actual jump height
@Pefeper
@Pefeper 4 дня назад
Time to peak should not affect the jump height. Have you tried copying the code from the Github gist to make sure the equations are correct?
@JuhoSprite
@JuhoSprite 3 дня назад
@@Pefeper ok good so it was something with my code then. I haven't tried using your entire player template. I just ended up not using this method and going back to the guessing game. I do like where my player physics is going tho rn.
@JuhoSprite
@JuhoSprite 3 дня назад
@@Pefeper also thanks for still replying to comments years after the videos release. really nice of you gotta appreciate that.
@Pefeper
@Pefeper 3 дня назад
@@JuhoSprite of course!! Good luck with your project!
@darknight-mn8fo
@darknight-mn8fo День назад
I tried to use this for my game. The problem I ran into was that when a jump is intiated and the player collides with a wall before jump_height is reached, the player slides up the wall, till the jump_height, before sliding back down. Is there a way to stop the slide upward, when colliding with the wall. Im new to godot and this is my first game I am developing
@darknight-mn8fo
@darknight-mn8fo 8 часов назад
Nvm, found the solution. Thank you for the tutorial
@1nopinate
@1nopinate 2 года назад
where can i get the jump height counter sprite he use i want to use that as reference
@Pefeper
@Pefeper 2 года назад
I actually made it myself! Let me find a good place to upload it and I'll add a link in the description
@1nopinate
@1nopinate 2 года назад
@@Pefeper wow didnt expect you to actually reply.... thanks man and very nice video i learn a lot from you man
@wash99
@wash99 3 года назад
Subed
@1nopinate
@1nopinate 6 месяцев назад
its 2024 and i still havent get the link for that ruler assets xD
@Pefeper
@Pefeper 6 месяцев назад
After 2.5 years I have finally uploaded a copy of it to Google Drive, thanks for reminding me! drive.google.com/file/d/1iJ2LDDIQTHzo6HJT_YGEeLugkr-1_w0Q/view?usp=sharing
@ogpandamonium
@ogpandamonium Год назад
How could I change this to jump higher the longer you hold the jump button?
@Pefeper
@Pefeper Год назад
You'd want to do everything just the same, except when the player releases the jump button, return a higher gravity value in get_gravity. So, when the player releases the jump button, they start to fall faster, eventually moving downwards at which point you can apply normal fall gravity
@ogpandamonium
@ogpandamonium Год назад
@@Pefeper Thank you!
@meeklazytitan6950
@meeklazytitan6950 Год назад
nvm im done subscribe to this man
@zacrenner5121
@zacrenner5121 2 года назад
Division By Zero in operator '/'.
@Pefeper
@Pefeper 2 года назад
What line was that on? Did you make sure you set all the variables?
@zacrenner5121
@zacrenner5121 2 года назад
@@Pefeper it was on the first line and it turns out I'm a dunce. I instanced the scene into my world to test, but was then trying to change the variables in the main scene instead of the instanced one, so all the variables on my instanced scene were still zero. I'm good now XD thank you for the tutorial!!!
@Pefeper
@Pefeper 2 года назад
@@zacrenner5121 No problem, mistakes happen! Glad you got it figured out, and thanks for watching
@viktorhugo1715
@viktorhugo1715 5 месяцев назад
why to multiply gravity by delta in an physics process call? it's called in a pre determinated times per second diferently from process
@Pefeper
@Pefeper 5 месяцев назад
The delta time between physics updates isn't guaranteed to be perfectly consistent, so it's best to still multiply time-dependent variables by delta
@viktorhugo1715
@viktorhugo1715 5 месяцев назад
@@Pefeper oh, thanks for the fast answer! Did not knew it wasn't perfectly consistent, thanks for the information. Ur videos are great :>
@pipacombate393
@pipacombate393 3 месяца назад
Bro I wanted this but with walking/running action instead, I wanted to be able to specify how long until the character reaches max velocity and (after the player let go of the run button) how long until the character loses all its velocity
@edgarvas2108
@edgarvas2108 20 дней назад
for my game, i did this: direction is either -1, 0, or 1, depending on the state of the input axis for movement in the ready function, set accel_rate to be top_speed / acceleration_time, and the same with decel_rate and deceleration if direction != 0: velocity.x += accel_rate * direction * delta velocity.x = clampf(velocity.x, -top_speed, top_speed) else: if velocity.x > 0: velocity.x -= decel_rate * delta velocity.x = max(velocity.x, 0) elif velocity.x < 0: velocity.x += decel_rate * delta velocity.x = min(velocity.x, 0) move_and_slide()
@pipacombate393
@pipacombate393 20 дней назад
@@edgarvas2108 tysm bro🙏
@edgarvas2108
@edgarvas2108 17 дней назад
@@pipacombate393 ur welcome bro
Далее
Jump Physics  [Design Specifics]
4:53
Просмотров 121 тыс.
A new way to generate worlds (stitched WFC)
10:51
Просмотров 520 тыс.
How I do Jump Buffer in Godot in 4 minutes!
4:27
Просмотров 7 тыс.
How To Fail At Game Feel
3:48
Просмотров 65 тыс.
The Most Controversial Children's Book in History
40:38
This Problem Changes Your Perspective On Game Dev
25:51
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 512 тыс.
Do THIS Before You Publish Your Godot Game
3:33
Просмотров 156 тыс.
Math for Game Programmers: Building a Better Jump
25:43
One Week of Learning Game Dev in Godot
15:27
Просмотров 33 тыс.