Learn Bevy! Custom Components/Resources and Gameplay (part 2)

Поделиться
HTML-код
  • Опубликовано: 4 авг 2024
  • Welcome to part 2 of my intro to Bevy series. Sorry for the delay on this part, I just moved into a new house and had no internet for a week!
    Discord Invite: / discord
    Patreon: / logicprojects
    Github: github.com/mwbryant/logic_far...
    Chapters:
    0:00 Intro
    0:14 Custom Component
    1:31 Camera Settings
    2:05 Custom Resources
    3:14 Pig Spawning
    3:55 Filters
    4:51 Pig Spawning Impl
    6:08 Pig Lifetimes/Timers
    7:14 Entity Queries
    8:34 Final Product
    8:43 Outro
  • НаукаНаука

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

  • @radekn.835
    @radekn.835 2 месяца назад +1

    It was just a couple lines of code, but making my pixel pigs run on the screen made me happy! Thanks for the tutorial!

  • @emartinez__
    @emartinez__ 11 месяцев назад +2

    As someone who just got interested in Rust and game development, this was the perfect starter resource. Thank you!

  • @RogersNucleus
    @RogersNucleus Год назад +5

    Already looking forward to part 3!
    Really pleasant to watch the video, the code snippets are really nice presented.
    Thank you for all the time you invest to make them look polished

  • @jacques-dev
    @jacques-dev Год назад +5

    Yay part 2! Good job.

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

    Nicely explained
    I am excited for the next one

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

    I really like your Series about bevy it is really helpful for me as a beginner.

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

    Great work

  • @DejaimeNeto
    @DejaimeNeto Год назад +5

    Yes

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

    Very awesome, great tutorial.

  • @tenthlegionstudios1343
    @tenthlegionstudios1343 Год назад +5

    Awesome, more .11 Bevy! I hope the new job is treating you well (think I remember you saying you were switching a while ago). If onboarding is going well, and you have a good team, then that means more Bevy content for us :) .

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

      I start the new job very soon and I couldn't be more excited :) Thank you!

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

    Thanks! Amazing Tutorial!

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

    Awesome tutorials, thanks for the great resource to get into rust/bevy, there's not much out there!

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

    Great tutorial!

  • @mikkelens
    @mikkelens Год назад +4

    Every video I get a little more comfortable reading Query etc.
    I hope eventually it will all just click for me and I can work with Bevy queries with the same confidence I write MonoBehaviour code in Unity.

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

    Thank you!

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

    amazing

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

    i need more!

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

    Since using commands to spawn stuff doesn't actually happen when its called but rather sometime at the very end of each tick I personally like to emit events, e.g. as it's a very common and often generic thing. A Spawn event with a position and texture attribute is a generic way to handle this case for example

  • @MatheoxMattheox
    @MatheoxMattheox 11 месяцев назад +1

    Please make more videos!

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

    What is the practical difference at 4:00 between using a filter and a tuple of components? So for example, what is the difference between Query for the pigs versus Query for the player? To me both seem to return a set of component tuples (ie entities) that only have both of the specified components.

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

      The With version doesn't give read access to Pig. So we're not reading pigs value, just ensuring the entity has a pig component. Practically this means another system can be mutating pig components while this runs but it's also good for expressing that this system doesn't depend on the value of pig. It's a good practice to get the minimum of mutable/read only/with that you need

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

      @@logicprojects oh that makes a lot of sense! And I can see how this can come in very useful! Thanks for the quick answer!

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

    the `commands.spawn()` method in the docs it says, it accepts a Bundle trait as parameter,
    but why is that we need to supply an object that implements Component trait instead of Bundle ?

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

      If you look at Bundle in the docs you'll see it is implemented for components and tuples of components (and tuples of bundles). Bevy puts a lot of work into things like this to make them ergonomic and intuitive. Most of the tuples implementations are done with macros under the hood

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

    I thought that I have understood the concept of ECS in bevy. So far, the my understanding is:
    [Entity]
    a unique identifier that may or may not attached to a Component or multiple Components. It does not contain any data, it is like an index or identifier to a Component or a bunch of Components shall I say.
    [Component]
    the data structure defined by developer to be used in the game. This data structure is meant to be registered in the StartUp schedule, which then later can be queried in the Update schedule. Suppose, two instances of the same type i.e (a struct) are meant to be queried in the Update schedule, we must create two different Components instead of one. If only one Component is defined i.e derive from Component class or interface (idk), the instances of that Component cannot be queried in the Update schedule. So, in ECS, multiple instances of a Component are absolutely obsolete.
    [System]
    a function that is defined with a set of parameters defined by bevy ecosystem that we want to use in a particular function/system. For example, we might need instance of `Command` structure.
    So, we declare it in the parameter.
    With the help of AI, it says i have 235 entities. what are the ways to reduce the entity number. I wanted to create a 4 player chess game

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

      For components you can create new entities with your components during update as well. Components are attached to entities so you can have many copys of each component but only one for each entity. Resources are what's constrained to 1 globally.
      For your chess game that's a totally reasonable number of entities. Bevy can handle much more than that without any problem

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

    i defined a system called pig_movement for the homework . Each iteration a random direction will be picked to determine the movement of a pig. Could that be a good approach? Function looks like this:
    fn pig_movement(
    mut pigs: Query,
    time: Res,
    ) {
    let right = Vec2::new(1.0,0.0);
    let left = Vec2::new(-1.0,0.0);
    let down = Vec2::new(0.0, 1.0);
    let up = Vec2::new(0.0, -1.0);
    let direction = [right, left, down, up];
    for (mut transform, pig) in &mut pigs {
    let random_index = rand::thread_rng().gen_range(0..=direction.len()-1);
    transform.translation.x += direction[random_index].x * pig.speed * time.delta_seconds();
    transform.translation.y += direction[random_index].y * pig.speed * time.delta_seconds();
    }
    }

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

      That definitely looks like a good approach! If you want smoother movement you can also use timers to only select a new direction every few seconds or something

  • @AM-yk5yd
    @AM-yk5yd 11 месяцев назад

    For fun sake I tried to decompose everything as much as possible.
    I thought despawning happens at the very end of the frame(I think unity does so), it also happened between PreUpdate and Update.

    • @logicprojects
      @logicprojects  11 месяцев назад +1

      It actually happens whenever the apply_system_buffers system runs which is periodically throughout the frame (including the times you spotted)

  • @Mekuso8
    @Mekuso8 11 месяцев назад

    Watching this series, I'm not sold on ECS. To me, it just seems unnecessarily convoluted. One idea for a future video would be to provide examples where ECS actually provides real value compared to a non-ECS game engine.
    Also, in the code in this video, did you reload the pig image file every single time you press space?

    • @logicprojects
      @logicprojects  11 месяцев назад +1

      It's not any more convoluted than Object Oriented game design, it's just a different approach that I enjoy a bit more than the old way. For the pig image, bevy asset system caches what images are loaded. It might be dropping the image if there are no pigs on screen so I usually would hold a handle just to ensure it never gets dropped but most the time there is no problems there in practical games.

  • @comradechonky6328
    @comradechonky6328 11 месяцев назад

    bruh the money is decreasing but the player can still spawn pigs

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

    new bevy engine is extremely lack of documents and comments in engine code. 😖

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

      What do you mean? The engine has docs for just about everything now. Go to the docs page and the only things that are sometimes lacking is deep rendering pieces. Also for engine code internally the git blame usually links to the PR with detailed explanations of why a feature exists

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

      @@logicprojects for example, SystemSet. no documentation for trait methods, no documentation for derive attribute, and also no documentation for SystemSet schedule logic.

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

    nice explanations, although the "game" is pretty boring😂
    I hope this series will be useful.
    P.S. video quality is still problematic, I'm shocked by the fact we have to deal with such problems in 2023😢

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

      It's a start! Bevy doesn't have the same built in niceties that unity has so it takes a bit to get something impressive. Also I thought the video quality was fixed by uploading in 4k... It looks better when I watch it back now

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

      ​@@logicprojectswell, for 1080p the quality is very similar to the previous, same square artifacts. For 4k they are present too, but now they are 2 times smaller.

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

      @@logicprojects Video looked good to me :) . 1080p and 4k.