Collisions, Jumping and Gravity | Create an Amazing Game with Flutter & Flame

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 137

  • @Jerry0721
    @Jerry0721 13 дней назад +2

    I am learning flutter in Korea. I appreciate your videos! It's a little bit hard, but I'll try my best. Thank you😊

  • @cf6979
    @cf6979 Год назад +19

    You are breaking ground in the Flutter/Flame community and showcasing it in an easy to learn way.👍 Thank you!

    • @Spellthorn
      @Spellthorn  Год назад +2

      Glad you think so! Trying my best to figure it out and help other 😁

  • @airkobin
    @airkobin Год назад +1

    ちょうどFlutter/Flameの勉強をしたかったので、とても参考になりました!
    ありがとうございます。
    これからも動画楽しみにしています

  • @ricardomejias7957
    @ricardomejias7957 Год назад +2

    This is a great series, I´m really enjoying how simple and practical your approach is, coding along line by line without crazy copy pasting or pre-coded files. I am already a Flutter developer, so focusing only on the Flame specific features like you´ve been doing resonates with my needs. Thanks and keep on the good work!

    • @Spellthorn
      @Spellthorn  Год назад +1

      I'm glad you're enjoying the series so far. Yea I always hated tutorials where they copy paste a lot, like umm what does that do and why. I'm still working on having a good structure, I work out this code before hand sometimes takes hours to figure out something then struggle to remember the order I did it, so I've started taking notes while coding

    • @ricardomejias7957
      @ricardomejias7957 Год назад +1

      ​@@Spellthorn another thing I forgot to mention: displaying your keyboard input on the recording while typing is a great touch, really helps catching those keyboard shortcuts

    • @Spellthorn
      @Spellthorn  Год назад

      Yea I was glad I found that tool definitely helps out as I do use a lot of short cuts, sometimes I forget to turn it on though and realize later

  • @gamerguide325
    @gamerguide325 Год назад +2

    I was waiting for this video, Amazing work. There are some videos available for flame and flutter together but most of them are outdated. Iam working on a 2D game and this series has been a very helpful tool for my work. Thanks 🙏

    • @Spellthorn
      @Spellthorn  Год назад

      I'm glad they have been helpful, that's why I wanted to make the series as I felt stuck when trying to learn flame myself

  • @emadeddineibo1842
    @emadeddineibo1842 Год назад

    Finally! I was eager to see this part 😍
    I't gonna be a great evening today 😁

    • @Spellthorn
      @Spellthorn  Год назад +1

      Yes, it was a long time coming 🤣 hoping the rest will be easier 😁

  • @arnovanzyl5976
    @arnovanzyl5976 Год назад +2

    This series is absolutely BRILLIANT! Thank you

    • @Spellthorn
      @Spellthorn  Год назад

      Thank you 😊 glad you're enjoying it. Next episode will be out tomorrow 😁

  • @tima9738
    @tima9738 Год назад +2

    Thank you for that videos! It's easy to learn by them!
    Just a tip: Flutter has geometry classes like Rect that has a method called 'overlaps()', and you could create rects and check if they overlap each other easily.

    • @Spellthorn
      @Spellthorn  7 месяцев назад

      Hmmm I wonder how that would work, thanks 😊

  • @confusedpineaple
    @confusedpineaple Год назад

    This was definitely a long one but i'm really glad you were able to figure it out!

  • @hilgerto
    @hilgerto 8 месяцев назад

    Thank you very much for the effort you put in

    • @Spellthorn
      @Spellthorn  8 месяцев назад

      Glad you enjoyed it! 😊

  • @Zerocchi
    @Zerocchi 5 месяцев назад

    I'm late to the party but great tutorial so far! I've learnt a lot about Flame from your videos. If you want to shorten your code a bit in 19:00, now you can make use of extension helper getters provided
    _final platform = CollisionBlock(position: collision.position, size: collision.size, isPlatform: true,);_
    Thank you for this tutorial :)

  • @muhammadissasabbagh1540
    @muhammadissasabbagh1540 Год назад

    Finally 🎉🎉🎉🎉 this is better than expected

    • @Spellthorn
      @Spellthorn  Год назад

      Sorry for the delay. Definitely was a rough road. But feel great coming out on the otherside. 😁

  • @minseokjeong1881
    @minseokjeong1881 Год назад

    So goooooooood. Thnx for upload about flame video things.❤

    • @Spellthorn
      @Spellthorn  Год назад +1

      Glad you enjoy it! We have a lot more to do 😁

  • @YaxineZone
    @YaxineZone Год назад +1

    the issue of Player getting pushed outside the game frame was resolved by checking the update order. Proper ordering of update operations is crucial in game development to ensure that each step is executed in the correct sequence.

    • @AMANKUMAR-km5ck
      @AMANKUMAR-km5ck 2 месяца назад

      how can i fix it, my player is going out of frame

  • @mohammednasir2064
    @mohammednasir2064 5 месяцев назад +1

    Hello sir. Thank you for the great tutorial..but..how can I do a player double jump? I tried to figure this out, but when the player pressed the "space" button to trigger the jump function...the game engine continued counting until the player returned and touched the ground...so I was not able to add an int variable to count the number of presses on the "space" button. Although in the "hardware_keyboard" class
    There are Event like "KeyDownEvent" and "KeyUpEvent" but I couldn't get any of them to work.
    thank you

  • @Amankumar_Raone
    @Amankumar_Raone 7 месяцев назад

    just wow,thanx for shearing❤❤

    • @Spellthorn
      @Spellthorn  7 месяцев назад

      Thanks for watching!

  • @user-lc8oe1xi3e
    @user-lc8oe1xi3e 9 дней назад

    Hi, i am not able to jump through the left platforms, but platforms on the right side i dont have any problems with.

  • @whatsonrightnow
    @whatsonrightnow 9 месяцев назад +1

    Nice series. Just a comment about using super in the constructor. If you are just passing the value through to the super constructor, you can just use *super.position* as the parameter to the constructor. So for example the entire CollisionBlock constructor can just be: *CollisionBlock({super.position, super.size, this.isPlatform = false});*

    • @Spellthorn
      @Spellthorn  8 месяцев назад

      That's good to know. Thank you 😊

  • @alfredoquinteroolivas7908
    @alfredoquinteroolivas7908 2 месяца назад

    I took your series as my introduction to game development, and I just have to say: Great work! I just had a problem with the collisions with the blocks. I put a block just two tiles above the ground, and when the player jumps below it while running to the right or left, the collision throws the player to the side instead of moving him down. I haven't figured out how to solve it, and I would appreciate any advice. Thank you!

  • @swastikpoojari5468
    @swastikpoojari5468 4 месяца назад +1

    help me out, after implementing vertical gravity whenever i am moving my character it goes straight out of map, i am stuck couldn't figure out the issue

    • @AMANKUMAR-km5ck
      @AMANKUMAR-km5ck 2 месяца назад

      in the update method, make sure that gravity function should be called before vertical collision function

  • @b.g.9023
    @b.g.9023 3 месяца назад

    may you get tutorial link for rectangle collisions? 23:39

  • @sitdownandcode
    @sitdownandcode Год назад +1

    you can use null aware operator instead of if statement like this:
    for (final spawnPoint in spawnPointsLayer?.objects ?? [])

    • @Spellthorn
      @Spellthorn  10 месяцев назад

      Great to know thanks 😊

  • @AMANKUMAR-km5ck
    @AMANKUMAR-km5ck 2 месяца назад

    Jump in the middle of air is not working. Plz. help

  • @nixonqqqqqqqqqqqwiguna8772
    @nixonqqqqqqqqqqqwiguna8772 8 месяцев назад +1

    Is there a tutorial for use on mobile for the jump section so you can jump using the jump button?

    • @kyawnai
      @kyawnai 7 месяцев назад

      You can find it on episode 8

    • @Spellthorn
      @Spellthorn  6 месяцев назад +1

      thanks for the help 😊

    • @Spellthorn
      @Spellthorn  6 месяцев назад +1

      like the other view stated in episode 8 😊

  • @jhovblack
    @jhovblack Год назад +2

    Hi! First of all, thank you very much for this tutorial, it has been great so far. I played around with the Godot engine but I felt without control of many things so I'm giving a try to Flame.
    My question is about the collisions, I'm wondering why didn't you use the HasCollisionDetection mixin from Flame. Maybe I missed the explanation from the video, sorry if that was the case.
    Thanks again for your effort and for sharing it!

    • @Spellthorn
      @Spellthorn  Год назад +3

      I'm glad you're enjoying the series. I've used godot before but yea definitely liking Flame.
      So the reason that we didn't use the built in collisions is because you're always colliding which causes many errors so it was easier to check the horizontal collision first, then apply the gravity then check vertical collision rather than the built in collision always checking it. There's probably a way to use the built in collision but I tried figuring it out for weeks so just gave up 🤣 in the future episodes we do use the built in collision though 😁

    • @jhovblack
      @jhovblack Год назад +1

      @@Spellthorn Thanks for your answer! Glad to hear that you are using it in following episodes (because I paused your video and went to the docs to use the mixin and now I'm kind of stuck too 😂the player stops but just for a while).
      Keep up your good work! 💪

    • @Spellthorn
      @Spellthorn  Год назад +1

      Yea there is a tutorial to use it with a circle hitbox and it works well. But for rectangle hit box it just doesn't work right. So not worth the hassle to figure it out 🤣

    • @jhovblack
      @jhovblack Год назад +1

      @@Spellthorn Finally I made it work well with the rectangle hitbox reducing the box size and a couple of flags to avoid changing the position on the collision. I'll continue with the gravity part hoping that my code will not be that different to yours 🤞

    • @Spellthorn
      @Spellthorn  Год назад

      Thats awesome, yea gravity is what breaks everything with the built in collision, let me know if you find a way 😁

  • @ДенисГерасименко-д1к
    @ДенисГерасименко-д1к 4 месяца назад

    What is the "current" variable? from where you take it?

    • @Klausi-uq4xq
      @Klausi-uq4xq 4 месяца назад

      Ist build in from SpriteAnimationGroupComponent

  • @cyrilchyi
    @cyrilchyi Год назад +1

    Thanks for your great video! I've learned a lot from your video. However I think I've found a bug about the gravity. You've updated the velocity according to the gravity. `velocity.y += gravity;`. However, just like you mentioned in your previous videos, you should multiply the gravity by dt. Otherwise, our player will jump differently in diffrent fps.

    • @Spellthorn
      @Spellthorn  10 месяцев назад

      Yea gravity caused me a lot of issues. Never could find out why

    • @jeremiekleiber7181
      @jeremiekleiber7181 Месяц назад

      I've been stuck on this jump height issue with FPS differences between different phones for three days. You've been a huge help! Thanks for your comment, buddy!

  • @EdsonAmorinaJunior
    @EdsonAmorinaJunior 9 месяцев назад

    Hi, I have 2 issues: the movement does not work when i press A or D; and may arrows is wrong (its like my keyboard was Landescaped... lol), my Up arrow acts like Right arrow, my Down arrow as Left arrow, my Right arrow as Down, and the Left as Up.
    Anyone knows how to solve? :) thanks

  • @ajitkrmaurya
    @ajitkrmaurya Год назад +1

    While testing the application properly, the character is getting away from the box. It seems it's working perfectly in the video, but in my application, it getting away from the box.
    Any suggestions?

    • @Spellthorn
      @Spellthorn  Год назад

      When you say getting away from the box what do you mean? What box? Like the player is farther from the object?

    • @YaxineZone
      @YaxineZone Год назад +1

      its about methods ordering in the update

    • @你好-v2u
      @你好-v2u 9 месяцев назад +1

      @@YaxineZone thanks a lot! it's working for me. I didn't notice that🤣

  • @Squinnmb
    @Squinnmb Год назад

    I don't have exp in game development but I can't image it's normal to have the _checkvertical/horizontalCollision() type methods where you loop through ever collision block to check if it's overlapping the character. Isn't there an event listener/callback style way to achieve?

    • @Spellthorn
      @Spellthorn  10 месяцев назад

      Yea it could be bad but haven't found a better way to check it. It has built in collection ability but that caused way too many issues so went this approach

  • @informativeinformations9580
    @informativeinformations9580 Год назад

    Just amazing ❤❤

  • @shaiherman9872
    @shaiherman9872 Год назад

    Great tutorial series I'm really enjoying it! I have an issue when running it as a macos app. When I use the keyboard I hear a system sound on every click. Any suggestion how to overcome this?

    • @Spellthorn
      @Spellthorn  10 месяцев назад

      Hmm I'm not sure about Mac sorry

  • @gogu2120
    @gogu2120 Год назад +1

    thank you for your video!!! but i have a question about my bug. When i start the game, if i press leftarrow button, the player teleport to the lefttop corner ( x: 48 y: 48) and when i press rightarrow button, player suddenly goes out of the map and it falls down out of the screen. I compared all of the codes of mine with your codes on the github but everything is fine. I don't know the reason why this bug happens. Do you know any solutions??

    • @Spellthorn
      @Spellthorn  Год назад +1

      This could be a collision issue as if it collides with bottom first it then moced you to the ends. Make sure your checking horizontal collision first then vertical otherwise this happens

    • @gogu2120
      @gogu2120 Год назад

      @@Spellthorn In player.dart file, i changed the order of _applyGravity function and _checkVerticalCollisions function in update function and it worked. the _applyGravity function should be the first. Thank you for your answer :)

    • @Spellthorn
      @Spellthorn  Год назад

      No problem, I'm glad you were able to fix it

  • @Pridzoyo
    @Pridzoyo 8 месяцев назад

    I did everything like you did in the video, but for some reason my character falls down and out of the level. There is no collision.

    • @Pridzoyo
      @Pridzoyo 8 месяцев назад

      Nevermind, I fixed the problem.

    • @Spellthorn
      @Spellthorn  7 месяцев назад +1

      Glad you were able to fix it 🙂

    • @AhmadHassan-d7s
      @AhmadHassan-d7s 2 месяца назад

      How did you fix it? Please let me know

  • @WayneRenbjor
    @WayneRenbjor Год назад +2

    Here is how you would use the built in collision detection without making your own: void _checkHorizontalCollisions() {
    final playerBounds = toRect();
    for (final block in collisionBlocks) {
    if (playerBounds.overlaps(block.toRect())) {
    if (horizontalMovement < 0) {
    position.x = block.toRect().right + playerBounds.width;
    } else if (horizontalMovement > 0) {
    position.x = block.toRect().left - playerBounds.width;
    }
    }
    }
    }

    • @Spellthorn
      @Spellthorn  Год назад

      I'll have to try that out thank you

    • @codemoor
      @codemoor Год назад

      its working thanks

    • @BrianMantel
      @BrianMantel 8 месяцев назад

      Works well. Thanks. Just a note that although you are using built-in overlap detection, there is a real collision detection system that uses callbacks.

  • @emadeddineibo1842
    @emadeddineibo1842 Год назад

    Just a tip, try to discover BonFire, it's completely compatible with Flame, and it provides many helpful functions. It's most used in RPG games, but still it might be useful.

    • @Spellthorn
      @Spellthorn  Год назад +1

      Yea I've seen that, I'm not a huge fan of using other stuff inside other stuff if I can avoid it, too much to keep track of 🤣

    • @emadeddineibo1842
      @emadeddineibo1842 Год назад

      @@Spellthorn I'm really excited to see the end version of this game, I'm sure you'll reach a place where you need State Management, storage, etc, that's what I'm looking for.
      Also, it would be nice if you present any idea how to make scrollable background, like in your game, imagine if the character can walk left infinitely.

    • @Spellthorn
      @Spellthorn  Год назад +1

      I've implemented scrolling background today actually 😁 also I've done the fruit too. 😁

    • @emadeddineibo1842
      @emadeddineibo1842 Год назад

      @@Spellthorn Can't wait to see it 😍

    • @Spellthorn
      @Spellthorn  Год назад +1

      Yea trying to figure out the Saws next 😁

  • @alimurtaza7438
    @alimurtaza7438 Год назад

    How can I play this game on mobile phone

    • @Spellthorn
      @Spellthorn  Год назад

      You can build for my mobile by running flutter build apk then plug in phone and do flutter install

  • @MmUQue
    @MmUQue Год назад

    Great work man! Thank you.
    I just had a problem, i got same constants than you but my character jumps really high, i dont know why :(
    I mean, i adjust the constants but i wonder why is different?
    Maybe its because behaves different depending each device, if so, how can we avoid that?

    • @shaiherman9872
      @shaiherman9872 Год назад +1

      In the video he set the jumpForce to 460 but somewhere along the way (maybe he edited the video) he changed it to 260, i saw the value it in the github project.

    • @Spellthorn
      @Spellthorn  10 месяцев назад

      I'm pretty sure I break the gravity here so different on different screens etc

    • @anandyerawar6473
      @anandyerawar6473 8 месяцев назад

      i was stuck on it too

  • @SaiduBundu-Kamara
    @SaiduBundu-Kamara Месяц назад

    Please don't apologies for making an awesome vid long lol

  • @tfozo
    @tfozo Год назад

    😮I was working on a thrust method of flying a player, I use a joystick component, however the Player doesn't fly towards the initial direction for a little while like any projectile then fall parabolically...but mine is completely stopped when I let go the joystick and gravity takes his soul almost instantly, how do u think I should approach this?

    • @Spellthorn
      @Spellthorn  Год назад

      Hmm. To me it sounds like you'd want to decrease your y velocity while holding the joystick so it keeps subtracting more and more. And then if let go then have gravity start. Which should start it at a lower number and increasing making it more smooth. Also clamping the velocity so don't fall too fast

    • @denilsonwashuma1987
      @denilsonwashuma1987 Год назад +1

      hey man, did you figure out the thrust method? could really use some help

    • @Spellthorn
      @Spellthorn  Год назад +1

      Thrusting up should just be as easy as keep subtracting from your why, while button is pressed. Then stop when letting go and have gravity do the rest.
      Something like
      If(thrust) {
      position.y -= thrustAmount;
      }

    • @tfozo
      @tfozo Год назад

      @@denilsonwashuma1987 nah I didn't solve it, I left another comment in this section.it seems, We kinda need to be the first to integrate our own ironman logic from scratch to Flame

    • @denilsonwashuma1987
      @denilsonwashuma1987 Год назад

      @@Spellthorn Thanks will try it out

  • @crazyvolt1660
    @crazyvolt1660 Год назад +1

    The video was amazing, but Im not a good student of physics, velocity, gravity and other stuff are hard to understand. 😄
    Im still try to understand them.

    • @Spellthorn
      @Spellthorn  Год назад +1

      I'm glad it was helpful, you'll get the hang of it 😁

  • @GarthFransman
    @GarthFransman Год назад

    I think the guys at Flame could use some of your input 🙂

    • @Spellthorn
      @Spellthorn  Год назад

      I'm in their discord, they have been a great help so far 😁

  • @theanimeclan27
    @theanimeclan27 Год назад

    My player is not spawning inside the game frame its getting pushed outside the game frame😥😥
    need help it is spawning on top of the game frame

    • @Spellthorn
      @Spellthorn  Год назад

      Is gravity causing it when it touches something to move outside the frame? Or when it first spawns is it spawning outside the frame? If its the first one turn off gravity and see if still happens. If its the 2nd one try a different position point

    • @theanimeclan27
      @theanimeclan27 Год назад

      @@Spellthornits the second and i tried different positions but it keeps spawning right above the spawn point on the frame

    • @Spellthorn
      @Spellthorn  Год назад

      Do you have the level.dart file correct, where you pass in the player position? Also make sure your passing your position to the super

    • @theanimeclan27
      @theanimeclan27 Год назад

      @@Spellthorn i am having problem like the portion below the vertical frames have become colliding like my player can't go below the frame too. like where ever i keep my vertical frame the portion below i collide

    • @Spellthorn
      @Spellthorn  Год назад

      Okay so it seems the error is definitely somewhere with the collisions, I have my code on github, it is a further version then where you are at but I would consider viewing that and seeing where your code may be different at least for the sections to where you are now

  • @informativeinformations9580
    @informativeinformations9580 Год назад

    Is it possible to create 3d games i.g. FPS games in flutter?

    • @gamerguide325
      @gamerguide325 Год назад

      You can make 3D games with flutter although it requires unity. Flame engine is not enough for 3D, it was designed to handle 2D game development.

    • @Spellthorn
      @Spellthorn  Год назад +1

      Flame is mainly for 2d games. You could probably make a 3d looking 2d game though

    • @informativeinformations9580
      @informativeinformations9580 Год назад

      @@gamerguide325 means I will have to create 3d models in Unity and logic in flutter insted of C# right?

    • @Spellthorn
      @Spellthorn  Год назад

      They mean if you want 3d you're better off using a game engine for that like unity. You wouldn't use flutter/flame for that

    • @informativeinformations9580
      @informativeinformations9580 Год назад

      @@Spellthorn oh, thanks understood

  • @coderlyfe1023
    @coderlyfe1023 Год назад

    your tutorials are great however refatoring in the middle of the series is extremely annoying

    • @Spellthorn
      @Spellthorn  Год назад +1

      Glad you're enjoying them. Sometimes when coding refactoring will need to be done. If there's a better way to do something, you should do it as early as possible otherwise you wont want to at the end or break stuff later if you do.

  • @dmitryandco.528
    @dmitryandco.528 11 месяцев назад

    Nice series! 🩵
    But why do you use switch statements when you don't need to and don't use them when you need to?
    And don't ignore type safety please, it hurts to see your dynamic parameters 🙏

    • @Spellthorn
      @Spellthorn  10 месяцев назад +2

      Well, I'm a self taught coder so ... I don't always use good practices, I use what works in the moment, and what I feel makes sense. This leads me to doing things wrong a lot in terms of common practices as I don't know what they are, but hey if it works it works right? 😂

    • @dmitryandco.528
      @dmitryandco.528 10 месяцев назад

      @@Spellthorn sure, the main thing is to make it all work, and you do it 🙌

  • @ioexeption
    @ioexeption Год назад +3

    This is a great series, I´m really enjoying how simple and practical your approach is, coding along line by line without crazy copy pasting or pre-coded files. I am already a Flutter developer, so focusing only on the Flame specific features like you´ve been doing resonates with my needs. Thanks and keep on the good work!

    • @Spellthorn
      @Spellthorn  10 месяцев назад +1

      Thanks, yea I'm not a fan of copy pasting tutorials either 😊