[Godot Tutorial] Basic Breakout! [P3] Instancing

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ค. 2024
  • Great Article on Vector Math: docs.godotengine.org/en/latest...
    Check out my popular GameMaker Book and GameMaker Courses: www.heartbeast.co
    Follow me on Twitch for GameMaker livestreams: / uheartbeast
    Follow my twitter: / uheartbeast
    Like my Facebook page: / heartbeast.studios
    Follow me on Tumblr: / uheartbeast
    GameMaker Tutorials on Reddit: / gamemakertutorials
    Thank you all so much for your support!
  • แนวปฏิบัติและการใช้ชีวิต

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

  • @kleinenboese395
    @kleinenboese395 7 ปีที่แล้ว +132

    At 16:35, to create a new scene from the Ball object on new version of Godot (as the icon shown by Benjamin not exist anymore): right clic on the name of the object and in the menu which opened, select "Save branch as scene" ("Sauvegarde la branche comme scéne" in French)

    • @bfranklin69
      @bfranklin69 7 ปีที่แล้ว +3

      Thank you! I spent twenty minutes searching on screen and through website documentations for it :D

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

      Thank you!

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

      Bump this plz

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

      Pierre-Louis LAMBALLAIS you are the best person

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

      Not all heroes wear capes

  • @evmaster114
    @evmaster114 3 ปีที่แล้ว +21

    3:52
    If you are using a newer version of Godot, instead of writing:
    var speed = get_linear_velocity().Length(),
    write
    var speed = linear_velocity.length()

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

    For those people that might get an error saying "invalid get index 'type' (on base 'input event mouse motion')". Don't use that. Instead use "if event is InputEventMouseButton:". The rest is fine.

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

      I couldn't get past this, thank you!

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

      thanks!, this held me for a while

  • @annief151
    @annief151 5 ปีที่แล้ว +12

    For those who are doing this with Godot 3.1. I've added some print commands, to see what the numbers are. Its a great way to see how Godot calculates its math. (Also explains why I didn't use the delta in the velocity variable)
    extends RigidBody2D
    class_name Ball
    const SpeedUp = 10
    const MaxSpeed = 300
    func _ready():
    set_physics_process(true)
    func _physics_process(delta):
    var bodies = get_colliding_bodies()
    for body in bodies:
    if body.is_in_group("Bricks"):
    body.queue_free()
    if body.get_name() == "Paddle":
    var speed = get_linear_velocity().length()
    var direction = position - body.get_node("Anchor").get_global_position()
    var velocity = direction.normalized()*min(speed+SpeedUp, MaxSpeed)
    set_linear_velocity(velocity)
    print(delta)
    print(speed)
    print(direction)
    print(velocity)
    if position.y > get_viewport_rect().end.y:
    print("Ball died.")
    queue_free()

    • @CalmProto
      @CalmProto 3 ปีที่แล้ว

      I added a print(" ")
      to get a blank line between those groups of numbers.

  • @pete275
    @pete275 8 ปีที่แล้ว +65

    you don't need to multiply delta by 100, what you should do is not apply delta when you calculate the new velocity. velocity is a unit that already includes time (ie pixels per second), so you're saying this is the new velocity, and the physics engine takes care of spreading that over the frames, you just have to provide the pixels per second value, not a pixels per frame (or tic) value

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว +3

      +pete275 Wait, the engine automatically applies delta to the velocity of a node? I've read through most of the documentation and I didn't see that in there. Can you show me where that is?

    • @pete275
      @pete275 8 ปีที่แล้ว +21

      It might not be anywhere because it's implied in the word "velocity" :) Normally your approach is correct, because you're saying, every frame, "move this many pixels". So to figure out how many pixels you have to move, you do "direction_normal * speed * delta_time". "speed" in this case is a number of pixels per second, and delta time is how many seconds went by since the last frame (usually something like 0.016). But in this case you're not saying "move x pixels every frame", you're saying "this is your new velocity". Note that you only set the velocity when the ball hits the pad, not on every frame. So you set the velocity (in a unit of pixels per second), and from then on the engine will move the ball according to that velocity, until it hits another body that might modify its velocity. The relevant code is around body_2d_sw.cpp:560, where it multiplies the final integrated velocity by p_step, and applies the new matrix to the body

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว +6

      Interesting, thanks. :)

    • @quaverBit
      @quaverBit 7 ปีที่แล้ว +4

      I hope I'm not too late but in Godot documentation for set_linear_speed says, and I quote: " DON’T SET THIS IN EVERY FRAME", and points to use _integrate_forces. Do you know how to implement this?
      After that, +pete275 is right in the way common physics work, the delta multiplication trick goes with the position increment by speed*delta(time), should be used if want to set position hardcoded.
      Note1: Godot documentation advises to don't hardcode the position because it could mess with the physics engine.
      Note2: +HeartBeast by the way, your maths could be wrong: speed + SPEEDUP*delta isn't the same as (speed + SPEEDUP)*delta.
      Thanks for the great tutorial and keep the awesome work.

    • @AnerLucero
      @AnerLucero 7 ปีที่แล้ว +3

      Another way to see this is that: you were assigning a "displacemente = velocity * time" as the velocity.

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

    At 21:16, if you're using Godot 3.0 later, replace
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    with
    if event is InputEventMouseButton && event.pressed:

  • @rukna3775
    @rukna3775 4 ปีที่แล้ว +23

    ERROR: 28:26
    "Invalid get index 'type' (on base: 'InputEventMouseMotion')"
    SOLUTION:
    if(event is InputEventMouseButton && event.is_pressed()): works
    so 1 == 1 and 1 is int, '==' compares btw. values but 'is' gives if 1 is an integer

    • @not_herobrine3752
      @not_herobrine3752 4 ปีที่แล้ว +5

      What exactly do we do, replace your line with the sugesstion?
      Edit: Yep, do what this guy says and you are good to go

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

      YOU LEGEND! Perfect solution to the exact error I was facing. I'm so proud of this community lol

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

      @@ash7324 welcome

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

    It feels good to finish a tutorial and have everything work. Even though this is from 2016 this comments and community still keep it up to date fixing anything that's changed and offering helpful advice. Thanks for the tutorial that still holds up.

  • @uheartbeast
    @uheartbeast  8 ปีที่แล้ว +13

    Here is that article on Vector Math. I recommend reading it even if you don't plan on using Godot: docs.godotengine.org/en/latest/tutorials/vector_math.html

    • @RocaSeba
      @RocaSeba 8 ปีที่แล้ว

      +HeartBeast Would you say that Godot is better than GM?

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว

      +Sebastián Roca Nope. I would say they are both good. I would use GM for certain types of games and Godot for certain types of games. What type of game do you want to build?

    • @RocaSeba
      @RocaSeba 8 ปีที่แล้ว

      +HeartBeast I would like to build a 2d shooter like "Enter the Gungeon" or something similar, which one would be better?

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว

      +Sebastián Roca Personally I'd use GameMaker for that :)

    • @RocaSeba
      @RocaSeba 8 ปีที่แล้ว

      HeartBeast many thanks! greetings from Argentina! :3

  • @johanneantoine3976
    @johanneantoine3976 11 หลายเดือนก่อน +5

    in Godot 4, the Position2d node is now the Marker2d node.

  • @mr.hoothoot8758
    @mr.hoothoot8758 7 ปีที่แล้ว +11

    I am sooo blown away by how powerful, clean and organize godot is! the scene tab is insane, godot will make you feel unity being messy IMO (from unity before). Its really a great engine especially for 2d, i was aiming for 3d development, but 2d game play but i think its no longer necessary with godot :)
    Great tutorial, and i know you are working on game maker tutorial, but please don't also give up with godot, you make mind-blowing tutorials, thanks!
    Regards

  • @b.n.a546
    @b.n.a546 4 ปีที่แล้ว +10

    Just a friendly reminder to spell out position instead of using pos if you're using a newer version of Godot.

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

      I spelt all of them as position except one as pos by accident and I was wondering why it was crashing when the ball was colliding with things lol. 😂 anyways easy fix once I realised.

  • @djpeknuk
    @djpeknuk 6 ปีที่แล้ว +13

    I have used first three parts of this tutorial with Godot 3.0, and ended up with slightly different code which is included below. Changes that I have made:
    - "Mini Scenes" renamed to "Entities"
    - instead of multiplying SPEEDUP and MAXSPEED by 100 times, I have just deleted ".normalized()" part from direction
    ########
    # Ball.gd #
    ########
    extends RigidBody2D
    const SPEEDUP = 4
    const MAXSPEED = 300
    func _physics_process(delta):
    var bodies = get_colliding_bodies()
    for body in bodies:
    if body.is_in_group("Bricks"):
    body.queue_free()
    if body.get("name") == "Paddle":
    var speed = linear_velocity.length()
    var direction = position - body.get_node("Ancor").global_position
    var velocity = direction * min(speed + SPEEDUP * delta, MAXSPEED * delta)
    linear_velocity = velocity
    if position.y > get_viewport_rect().end.y:
    queue_free()
    ##########
    # Paddle.gd #
    ##########
    extends KinematicBody2D
    const BALL_SCENE = preload("res://Entities/Ball.tscn")
    func _physics_process(delta):
    var y = position.y
    var x = get_viewport().get_mouse_position().x
    position = Vector2(x,y)
    func _input(event):
    if event.is_action_pressed("click"):
    var ball = BALL_SCENE.instance()
    ball.position = position - Vector2(0, 16)
    get_tree().root.add_child(ball)

    • @MateusBergamin
      @MateusBergamin 6 ปีที่แล้ว

      did you delete the _ready function?

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

      yes, it's not needed in 3.0

    • @genesta541
      @genesta541 5 ปีที่แล้ว

      Thank you HeartBeast and djpeknuk.
      I had to make one small change. In Paddle.gd, instead of "if event.is_action_pressed("click")" I had to use "if event.is_pressed()".

    • @Arsyel
      @Arsyel 5 ปีที่แล้ว

      or --> if (event is InputEventMouseButton && event.pressed):

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

      Deleting "normalized" will just create another problem because then it can have whatever magnitude while normalizing it makes sure that your speed will indeed be the one you set in the constant. The error that he made is that he multiplied the speed by delta when the Godot game engine takes care of that

  • @makebritaingreatagain2613
    @makebritaingreatagain2613 5 ปีที่แล้ว +17

    Getting "Invalid get index 'type' on base: 'InputEventMouseMotion')." error?
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    does not work any more in Godot 3.0
    I changed it to
    if event is InputEventKey and event.get_scancode() == KEY_SPACE:
    The documentation for Godot is awful, and I'm not smart enough to figure out how to do this with the mouse,
    so this will have to do for now. It probably involves InputEventMouseButton
    does anybody know what the .get_scancode() equivalent would be for InputEventMouseButton?
    Edit:
    OK I'm a smart pony after all :P
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    can simply be replace with
    if event is InputEventMouseButton:
    and this shiz will work now :D
    Edit 2 Electric Boogaloo:
    K the previous code results in 2 balls, one for click, and one for release, use this instead:
    if event is InputEventMouseButton && event.is_pressed():
    This game be sweet now.

    • @ChrischoBoardgaming
      @ChrischoBoardgaming 4 ปีที่แล้ว

      Nonetheless, I'd wished that the Godot Docs were using example code with each method. It's written in a way that experts surely find quickly what they need to know. But for a game engine that strives to become a widely known and used product it still seems to target the wrong audience.
      If it weren't for tutorials like those offered by Benjamin or a handful of others, we'd have to rely on those few instructions in the Docs finding the rest out on our own. Maybe there's some kind of Darwinistic thought process involved -- let only those aspiring developers succeed who are the fittest in learning by trial and error... Life is (rather: for me has become) too short for dealing with lacking documentation.

    • @Not_Zelda
      @Not_Zelda 3 ปีที่แล้ว

      thank you! Now it works, it's so hard to follow this tutorial with the newer version...

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

    That helped me so much!
    Keep on making Godot Tutorials.
    I would like to see them all!

  • @ChrischoBoardgaming
    @ChrischoBoardgaming 4 ปีที่แล้ว +6

    After striking more complex game dreams off my list for the time being and settling for something I might actually be smart enough to complete, I managed to get a breakout game running by myself. The only thing I wasn't fond of was the way the player didn't have control over the ball's movement after hitting it.
    Your idea with that Position2d node sounds good and your results prove that it's a good way. When I have changed that in my code, I will make duplicates of my brick scene next and invent some new brick types that need to be hit more than once and earn the player more points. Considering what went on in classics like Arkanoid or Traz back in the good old days of C64 gaming, there's quite a lot to do yet... ;)
    Thanks for sharing this with us!

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

    already knowing about the vector math gave me a huge confidence boost because I was in precalculus and we leaned all about vector math.

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

    Thanks for the new video Ben. Keep up the great tutorials.

  • @quazar8633
    @quazar8633 3 ปีที่แล้ว +5

    I couldn't get the magnitude using "get_linear_velocity().lenght()" but I solved it using Pythagoras theorem.
    So I did "sqrt((get_linear_velocity().x * get_linear_velocity().x) + (get_linear_velocity().y * get_linear_velocity().y))".

    • @wesleynewcomb
      @wesleynewcomb 3 ปีที่แล้ว +3

      9 months later, but you spelled "length" wrong

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

      @@wesleynewcomb 9 months after your comment, but that deserves a like

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

      @@Prime_Rabbit ​ 9 months after your comment to that comment, but that also deserves a like

  • @Hybban
    @Hybban 8 ปีที่แล้ว

    Excellent job Ben, as always.

  • @mixchief
    @mixchief 6 ปีที่แล้ว

    Such a great tutorial. Perfectly paced and really easy to understand.

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

      Thank you very much! I've just started doing videos on Godot 3.0. Hopefully I can do a good job with them as well :)

  • @HalValla01
    @HalValla01 4 ปีที่แล้ว

    You explain everything so well. Just got yourself a new subscriber!

  • @makebritaingreatagain2613
    @makebritaingreatagain2613 5 ปีที่แล้ว +8

    Getting "Invalid get index 'type' on base: 'InputEventMouseMotion')." error?
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    does not work any more in Godot 3.0
    can simply be replaced with
    if event is InputEventMouseButton && event.is_pressed():
    This game be sweet now.

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

      Thanks! I have also encountered the same error.

  • @jared7650
    @jared7650 8 ปีที่แล้ว +16

    You can comment and un-comment code using ctrl+k
    Speeds up debuging

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

    Thanks for putting this together. I made one of these games using UE4. This engine was so much easier for this type of game.
    Looking forward to more on Godot if you get the time. :) :)

    • @gavmakesgames588
      @gavmakesgames588 7 ปีที่แล้ว +3

      Yea, but using UE4 to make Breakout is like using rocket fuel to power your car.

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

    1) Before i forget, in later versions get_pos is replaced by get_position() among others. please refer to the featured comment in th-cam.com/video/GncaMNv7Fso/w-d-xo.html
    2) the movie thing can be accessed by rightclicking the ball and clicking "save branch as scene"

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

    Great video as usual

  • @Erandros
    @Erandros 6 ปีที่แล้ว

    Thanks a lot for this, very easy to follow!

  • @cristianinujazznight3044
    @cristianinujazznight3044 4 ปีที่แล้ว

    Thank you so much for this tutorial. With the preload and instance part, I get in love of this game engine. Because, with Unity I did'nt get this. Godot Rules.

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

    you can also use export var instead of the constants, let the level designer edit those values without changing the code :p

  • @cadfoot568
    @cadfoot568 8 ปีที่แล้ว +13

    Godot Engine book by B. Anderson coming soon

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว +9

      +Ruslan Sleptsov (indieGEAR) Lol no. Hahaha. I'm working on updating my GameMaker book right now. Writing a book is a pain.

    • @cadfoot568
      @cadfoot568 8 ปีที่แล้ว

      +HeartBeast i was kidding...
      good luck with your book!

    • @Hybban
      @Hybban 8 ปีที่แล้ว

      +HeartBeast That is great news!

    • @ChrischoBoardgaming
      @ChrischoBoardgaming 4 ปีที่แล้ว

      I'd constantly question my motives and have trouble finding the motivation to write a book knowing that with the next version of Godot, a good deal of my explanations, code examples and screenshots were already invalid.

  • @harshkumar811
    @harshkumar811 6 ปีที่แล้ว

    I didn't multiply by delta because that seemed to me as changing the dimensions of velocity. It worked fine. I set SPEEDUP = 40, and MAXSPEED = 3000.

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

    this has been a great tutorial. i have had ZERO game dev or code writing experience and this was a great way to start.
    i wondering thought if there is anywhere i can find other files that i can find that are already pre-made so i can work on practicing writing the script for it?

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

    Thanks so much for the tutorial, I love the way you explain stuff.
    I'm using Godot 3.2 and it had some problem with this part of the Paddle script:
    func _input(event):
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    var ball = ball_scene.instance()
    ball.set_position(get_position()-Vector2(0, 16))
    get_tree().get_root().add_child(ball)
    So I did some searching on the Godot docs page and managed to get the function working like this:
    func _process(delta):
    if Input.is_action_pressed("MOUSE_BUTTON"):
    var ball = ball_scene.instance()
    ball.set_position(get_position()-Vector2(0, 16))
    get_tree().get_root().add_child(ball)
    But I had to setup MOUSE_BUTTON as a name for the mouse button input under Project > Project Settings > Input Map for this to work.

    • @marktriestolive1781
      @marktriestolive1781 4 ปีที่แล้ว

      thanks, also just learning godot and using 3.2
      when i click the left mouse button tho, it spawns in 4 balls. idk how to set that to 1 ball only.

    • @juaquimcalamiong8957
      @juaquimcalamiong8957 3 ปีที่แล้ว

      This one works for me but the problem is there's so many balls being made in 1 click. Does anyone know how to fix that?

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

      @@juaquimcalamiong8957 I had to make a global variable i.e. ("ball_alive") and reference that in the if statement. If left click and ball_alive == 0 then run that code and at the bottom of that code make ball_alive = 1
      if Input.is_action_pressed("restart_ball") && GameManager.ball_alive == 0:
      ball = ball_scene.instance()
      ball.set_position(get_position()-Vector2(0, 16))
      get_tree().get_root().add_child(ball)
      GameManager.ball_alive = 1

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

      @@trevorleesmith14 Thanks! So it releases a ball at 0 then immediately turns it to 1 so no additional balls would release upon holding the left mouse button right? Damn it’s been 6 months since I did this. I’m prioritizing my other hobby now so I haven’t really coded in a long time.

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

      @@juaquimcalamiong8957 That is correct!
      I have tried coding many times myself, but always get sidetracked. Hopefully I can stick with it this time.

  • @confusedstockimage9807
    @confusedstockimage9807 8 ปีที่แล้ว

    Do you could make some videos on the coding aspect of game development?
    Perhaps a video on how to learn GML or the process you go through to make a script.

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

    when next episode od godot, and what are you wanna do in this ep? I think you should do label which show us score and live, when live = 0 then show level hame over your score is

  • @harrison5161
    @harrison5161 6 ปีที่แล้ว

    If you can't find the movie button at 16:35 you find it by *right clicking object* then click *Save Branch As Scene.*

  • @etopowertwon
    @etopowertwon 6 ปีที่แล้ว

    The reason you had such slow speed was because of min(speed * delta, max_speed * delta). Essentially, you mulitplied max_speed(300) by 1/fps. So if physics fps is default 60, it would be velocity = min(direction*speed*delta, 5) and 5 is much lower than original velocity.

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

    That's a good method with the 2D point

  • @MrVininski
    @MrVininski 6 ปีที่แล้ว +9

    I can't seem to get past the point after adding this line "if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():" I get a "Invalid get index 'type' (on base: 'InputEventMouseMotion')." error! Did something change in Godot? I'm on v3.0

    • @MrVininski
      @MrVininski 6 ปีที่แล้ว +9

      Ok it seems to work by changing it to: "if event is InputEventMouseButton && event.is_pressed():"

    • @MrVininski
      @MrVininski 6 ปีที่แล้ว +4

      No worries, I always try to pass the solution on if I end up working it out myself :) After a while of search the docs you can eventually figure out most of the changes. I got stuck many times haha.

    • @rukna3775
      @rukna3775 4 ปีที่แล้ว

      if(event is InputEventMouseButton && event.is_pressed()): works
      so 1 == 1 and 1 is int, '==' compares btw. values but 'is' gives if 1 is an integer

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

    if anyone is struggling with how to create a scene from a node in the latest godot version just right click on the node and click on the "save branch as scene" option.

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

    how to display "game over " ?

  • @Warionator
    @Warionator 4 ปีที่แล้ว

    For any Unity users out there, would making a scene of the ball be the equivalent of making a prefab in Unity? Thanks!

  • @metgaming9545
    @metgaming9545 4 ปีที่แล้ว +5

    Nobody is born cool... expect of course....
    The people who comment about how to do this in the newest version

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

    Don't know if you saw something when you hit you left attack key there was a black ball came out!

  • @mendorigohan4851
    @mendorigohan4851 5 ปีที่แล้ว

    Is there anyway to program in lua? It looks like it would work, but I dont want to have to learn a whole new programming language.

  • @FelipeDJT
    @FelipeDJT 8 ปีที่แล้ว +4

    Hello, Ben. How are you today?
    I have one question (or maybe two) regarding the logic behind the ball control. Here we go:
    1. Getting the paddle's position instead of creating a Position2D node to get its position would not have the same effect?
    2. Why not apply an impulse instead of multiplying the delta?
    I am quite busy, so I did not have the chance to test it myself. Hope you can answer me.
    Cya, and I am a big fan of your work.

    • @naeemchowdhury6280
      @naeemchowdhury6280 4 ปีที่แล้ว

      Did you have time to test it 3 years later?

    • @ChrischoBoardgaming
      @ChrischoBoardgaming 4 ปีที่แล้ว

      The paddle's position would result in the paddle's origin coordinates every time, making the ball bounce up with the same direction vector. With Ben's method, different points on the paddle's surface are taken into account and, combined with the Position2d node, result in different direction vectors, making the ball bounce of the paddle depending on where the ball hit the paddle. At least, that's how I understood it.

    • @naeemchowdhury6280
      @naeemchowdhury6280 4 ปีที่แล้ว

      @@ChrischoBoardgaming this is 4 years old..

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

      @@naeemchowdhury6280 Does that fact make understanding the problem/solution obsolete? I learned stuff from a video that's four years old. I sometimes even learn stuff from books that are hundreds of years old.

  • @fl333r
    @fl333r 7 ปีที่แล้ว

    Idk wtf happened but I deleted the ball scene to create a new ball scene and rename it to xml but now I open the project and its missing due to dependencies and just crashes so I think I have to start over... is godot really doing this? I cant imagine wtf would happen if I did this by accident on a huge project, jessus.

  • @ahmedlimam2241
    @ahmedlimam2241 4 ปีที่แล้ว

    direction.x is so small when you hit it with the right side of the paddle

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

    is there any chance of a new vide on this project that can help to explain how to add a gameover screen or dialog popup, which might also server as a basis for the next level screen, I have tried several different approaches for popups but can not seem to get a handle on them

    • @ChrischoBoardgaming
      @ChrischoBoardgaming 4 ปีที่แล้ว

      You could do the following:
      - Create a node (e.g. Control), inside, have whatever needs to be displayed on the GO screen. Position it far down in the scene tree to have it above other game elements.
      - make this node invisible in _ready function (yournode.visible = false)
      - when, e.g. three balls have been dropped, call your GO function (game_over())
      - inside game_over(), you first set yournode.visible = true
      - still inside there you probably need to stop/pause any physics process (set_physics_process(false) currently works for me) in order to prevent the game from continuing
      - add a button inside and connect its pressed signal with your main code (_on_Button_pressed()) and have the game call up your init function to start again or your enter_name() function for any highscore list stuff ;)

  • @skylerplays2121
    @skylerplays2121 8 ปีที่แล้ว

    heart beast can youy do a tutorial on a game like flappy bird (launching objects from a controled point with controled speed and direction)

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

    As I guess the linear velocity is the same thing as speed in GM.

  • @efrenhernandez6343
    @efrenhernandez6343 4 ปีที่แล้ว

    So, I have the problem that the ball doesn't appear in the window of the game, it appears out of the windows(the game is still running); I believe that is a problem with de the snap or the grid, because I set te values in the script to (50, 20) and it does appear. I wish that one of you can tell what is wrong (sorry for my bad english)
    Pd: here is the code
    func _input(event):
    if event is InputEventMouseButton and event.is_pressed():
    var ball = ball_scene.instance()
    print(str(get_position()))
    ball.set_position(Vector2(50,20))
    get_tree().get_root().add_child(ball)

  • @xenjikls392
    @xenjikls392 8 ปีที่แล้ว

    Have you ever thought about making tutorials for unity2d?

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

    22:30 I managed to load BrickOne.xml but it now like Ball.xml a tab. I could not find a way to load it to part node World.

    • @roxforbraynz3127
      @roxforbraynz3127 7 ปีที่แล้ว

      For those that come after me, I figured this out. You can drag and drop the BrickOne scene from the file explorer onto the Bricks node to instance the scene like in the video.

  • @ferditolkes1724
    @ferditolkes1724 4 ปีที่แล้ว +3

    Hey, these videos are helping so much to understand how to structure Godot projects and especially creating them. I have stumbled upon two problems and I was not able to find my mistake yet.. The first problem is, that when the ball hits the paddle it bounces every time in the exact same direction back, so something with the anchor doesn't work.
    My other problem is the instancing of the ball. When I hit the mouse button it creates new balls but they are located under the paddle and shifted to the right (so now when i want to create new balls I have to go as much to the right as possible with the paddle). I don't know what I'm missing here.. Here ist my code, I hope you can help me guys.
    extends RigidBody2D
    const SPEEDUP = 4
    const MAXSPEED = 300
    func _ready():
    set_bounce(1)
    set_friction(0)
    set_physics_process(true)
    func _physics_process(delta):
    var bodies = get_colliding_bodies()
    for body in bodies:
    if body.is_in_group("Bricks"):
    body.queue_free()
    if body.get_name() == "Paddle":
    var speed = get_linear_velocity().length() #weil lin. velocity Vektor
    var direction = get_position() - body.get_node("Ancor").get_global_position()
    var velocity = direction.normalized() * min(speed+SPEEDUP, MAXSPEED) #kein delta weil speed schon Geschwindigkeit ist
    set_linear_velocity(velocity)
    if get_position().y > get_viewport_rect().end.y:
    print("Ball died.")
    queue_free()
    extends KinematicBody2D
    const ball_scene = preload("res://Mini Scenes /Ball.tscn")
    func _ready():
    set_physics_process(true)
    set_process_input(true)
    func _physics_process(delta):
    var y = get_position().y
    var mouse_x = get_viewport().get_mouse_position().x
    set_position(Vector2(mouse_x,y))
    func _input(event):
    if event is InputEventMouseButton && event.is_pressed():
    var ball = ball_scene.instance()
    ball.set_position(get_position() - Vector2(0,16))
    get_tree().get_root().add_child(ball)

    • @ferditolkes1724
      @ferditolkes1724 4 ปีที่แล้ว

      Okay I figured it out, the problem was that I forgot to place the ball in the same spot as his collsionshape and his sprite.

    • @MaskedRokho
      @MaskedRokho 4 ปีที่แล้ว

      @@ferditolkes1724 Thanks for the help, you were the only person could find that has the same problem with the ball going in one direction.

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

    I learned all the vector stuff at school. It's actually quite easy.

    • @ChrischoBoardgaming
      @ChrischoBoardgaming 4 ปีที่แล้ว

      Lucky you! For me, it's still a big mystery and I am hoping that it'll CLICK soon in my head... Any good newbie tutorials about that "vector stuff" you know of? ;)

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

    For anyone having an error pointing to:
    func _input(event):
    if event.type == InputEvent.MOUSE_BUTTON && event.is_pressed():
    var ball = ball_scene.instance()
    ball.set_position(get_position()-Vector2(0,16))
    get_tree().get_root().add_child(ball)
    Try changing it to this:
    func _unhandled_input(event):
    if event is InputEventMouseButton && event.is_pressed():
    var ball = ball_scene.instance()
    ball.set_position(get_position()-Vector2(0,16))
    get_tree().get_root().add_child(ball)

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

    is the godot engine efficient for 3D game development? very helpful tutorial btw!

    • @OtakuDragon53
      @OtakuDragon53 6 ปีที่แล้ว

      yes, there is some godot 3d tutorials that he made.

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

    The article on Vector Math is here: docs.godotengine.org/en/latest/learning/features/math/vector_math.html

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

    hi thnx i'm huge fan from tunisia i have only ine question i download Godot from steam and it's a different version of yours (2.1)
    my problem is i didn't find how to do the mini scene for the ball can you guys help out and thnx

    • @Antchu17
      @Antchu17 7 ปีที่แล้ว

      I have the same problem

  • @Johnin3D_
    @Johnin3D_ 5 ปีที่แล้ว

    Hey, im on GODOT 3.0.6 now(12/4/2018) and after the "body.queue_free()" line, inputting the script after that, the game doesn't run. Did I miss something?

    • @SoySasha
      @SoySasha 4 ปีที่แล้ว

      probably, but in some other place

  • @user-vb4eq4vx1q
    @user-vb4eq4vx1q 7 ปีที่แล้ว +2

    Hi Ben, I've been working on this project for about 2 days and once i finished scripting everything up to 28:50 and when i ran the script and clicked on my mouse i couldn't shoot the ball. if you have time please respond.
    Thank you
    P.S you're an awesome youtuber

    • @user-vb4eq4vx1q
      @user-vb4eq4vx1q 7 ปีที่แล้ว

      sorry, never mind I just went over my code and spotted the error.

  • @itmemo8617
    @itmemo8617 7 ปีที่แล้ว

    thank you

  • @Eragarev
    @Eragarev 6 ปีที่แล้ว

    Okay, so creating "Scene" of an object is the same as creating a Class? That doesn't seem too hard to understand. It sucks that I'm using a newer version of Godot, since a few key buttons seem to be in different places than they are in this tutorial. It took me awhile to find out how to create an object Scene, not to mention trying to group objects together all at once doesn't seem to work, I have to do it individually. That's also quite different than adding objects to an array or something, but I guess this is for those people who prefer to build their levels by drag and drop.
    Godot's language is a bit too foreign to me, so I'm not sure about this one..

  • @AndrewOBannon
    @AndrewOBannon 7 ปีที่แล้ว +8

    Do mini scenes seem like a prefab in unity?

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

    Sometimes the ball will hit a brick and bounce off but the brick does not disappear. Does anyone else have this issue or know what I could be doing wrong?

    • @fobria
      @fobria 6 ปีที่แล้ว

      same here.... been baffled for a couple days. None of my bricks disappear. Do ANY disappear for you?

    • @Jeff2207xx
      @Jeff2207xx 6 ปีที่แล้ว

      It seems that the bricks must be hit in order - can't understand why

    • @superjumpgamesstudio9094
      @superjumpgamesstudio9094 5 ปีที่แล้ว

      @@Jeff2207xx Checkout the part of the tutorial where has this code.
      #########
      # ball.gd #
      #########
      func _physics_process(delta):
      var bodies = get_colliding_bodies()
      for body in bodies:
      if body.is_in_group("bricks"):
      body.queue_free()
      Now rememnber for these to work Benjamin mention that on the nodes, you need to setup several things, first you need to group all of the bricks nodes, into a group (in godot 3.0, next to inspector tab, you have the node tab, you can add a group name to each node, needs to be repeated to every brick node).
      Additionally, there was the 2 settings to in the ball node (rigidbody2d) set contact_monitoring to on and set the contact_reported to 1.
      I think logically it means that if detects a collision, then the code on the paddle.gd the "body.queue_free()" will work to remove each brick collided.
      Don't know if this helped.

  • @saw_games
    @saw_games 3 ปีที่แล้ว

    Godot 3.2.3
    How to prevent ball from rotating?
    I'm already made:
    RigidBody2D/Phisics Material/Friction = 0
    It dosn't help. "Ball" still start to rotate after hitting an edge of Paddle

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

      Found the answer, set
      RigidBody2D/Mode = Character
      It helped. If somebody have a beter answer, it is wellcomed.

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

    Seems like creating scene from node functionality has been removed from godot 2.1 :(

    • @jasper1639
      @jasper1639 7 ปีที่แล้ว

      Yeah, I cant find it either

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

      Yeah this was tricky for me to figure out. Right-click on the node and select "Save Branch as Scene." This should provide the same functionality as the button in the video.

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

      Patrick Cole yeah, I figured it ou eventually. It`s really anoying the newer version is so much different.

    • @johnblunt6693
      @johnblunt6693 6 ปีที่แล้ว

      It's their trust me

  • @jacksoncampbell4291
    @jacksoncampbell4291 8 ปีที่แล้ว

    what language does godot use?

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

      Godot uses its own. It's a Python-derivative, so if you know the basics of Python they can apply here.

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

    if _event is InputEventMouseButton && event.is_presget_relative_transform_to_parent():
    can somebody tell me why doesn't this code work, and tell me please with what to replace it with

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

      please i can't run the game

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

      use this instead:
      func _input(event):
      if event is InputEventMouseButton:
      var ball = ball_scene.instance()
      ball.set_position(get_position()-Vector2(0, 16))
      get_tree().get_root().add_child(ball)

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

      @@foolishflamez thanks 🙏

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

      Np :) i got stuck on this for abit too lol

  • @harshkumar811
    @harshkumar811 6 ปีที่แล้ว

    Can I script in c++?

  • @ciu8265
    @ciu8265 8 ปีที่แล้ว

    Please complete the rpg tutorial

    • @Hybban
      @Hybban 8 ปีที่แล้ว

      patience is a virtue man. he will finish it.

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

    you spelled anchor wrong

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

    19:02 saving myself a timestamp, dont mind me

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

    hey, this tutorial was going great until this moment, probably one of the best I've followed to be honest, i'm sure i'm being stupid but I cant get passed the 27 minute mark, i've taken the advice of other commentators on the changes to godot 3 onwards, this is my code. I'm getting a "nonexistent function 'instance' in base GDScript" for the var ball line when i click and can't guess my way out of it this time. please tell me how i'm being stupid, thanks
    extends KinematicBody2D
    const ball_scene = preload("res://Scenes/Ball.gd")
    func _ready():
    set_physics_process(true)
    set_process_input(true)

    func _physics_process(_delta):
    var y = get_position().y
    var mouse_x = get_viewport().get_mouse_position().x

    set_position(Vector2(mouse_x,y))

    func _input(event):
    if (event is InputEventMouseButton && event.is_pressed()):

    var ball = ball_scene.instance() #ERROR HERE
    ball.set_position(get_position()-Vector2(0,16))

    • @supercoolemile6129
      @supercoolemile6129 4 ปีที่แล้ว

      wow, staring at this for an hour. really do not know what i'm doing wrong, i;'m an idiot. send help

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

      @@supercoolemile6129 Hey! No worries! I'll do my best to help. so it seems you are loading Ball.gd instead of the Ball scene. Are you using .tscn for your scenes? I don't remember which file extension I used. You just want to make sure to load the scene instead of the script file in your preload. The error messages is saying that a gdscript doesn't have the instance function and that is because instance is only a function for scenes. Does that make sense?

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

      @@uheartbeast Hey, thanks for the reply, I'm really enjoying your tutorials, this is the furthest i have ever gone making a game to date. Your advice worked perfect, i was going mad trying to find what was wrong, i didn't notice i was loading the wrong thing, its going to teach me to organise things better in the future and i definitely learnt something unforgettable about Instancing. Thanks again

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

      @@supercoolemile6129 Glad I could help! It is always frustrating to get stuck. I've been there before. A lot of times haha.

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

    FAKE!!!! there is a floating mic in the bottom right corner. 0:00 through 43:59:20

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว

      +Game Jam! SHHHHHHHH!

  • @josevicente2106
    @josevicente2106 7 ปีที่แล้ว

    Here another maths
    if body.get_name() == "Paddle":
    var texture = body.get_node("Sprite").get_texture()
    var paddleWidth = texture.get_width()
    var paddleX = body.get_pos().x
    var d = (get_pos().x - paddleX)
    # 0.6 es el % del angulo para que no sea totalmente 0º
    var vxFactor = (d / (paddleWidth * 0.5)) * (0.6)
    var angle = (PI/2.0) * (1 - vxFactor)
    var vx = cos(angle) * MAX_SPEED
    var vy = sin(angle) * -MAX_SPEED
    set_linear_velocity(Vector2(vx, vy))

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

    Hey please do rpg maker series btw thx for that series

    • @uheartbeast
      @uheartbeast  8 ปีที่แล้ว +4

      +Brad Hrad You're welcome :) More GM RPG videos are on the way.

    • @GplSinner
      @GplSinner 8 ปีที่แล้ว

      +HeartBeast you are a great at explaining stuff and I didn't mean game maker I meant a cool engine simple called rpg maker it is awesome but if no thanks for reading and replaying

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

      +Brad Hrad hell its not awesome really dont use it to make games please or ill kill myself

    • @GplSinner
      @GplSinner 8 ปีที่แล้ว

      ok ok jesus calm down ok he will not
      god some people man (jk)

  • @coreycollins9620
    @coreycollins9620 7 ปีที่แล้ว

    hypotenuse would be the least complicated thing said here. lol

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

    nice floating mic! can i get one!
    (lol)

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

    it's called Godot bro.

    • @OtakuDragon53
      @OtakuDragon53 6 ปีที่แล้ว

      its called godot, but pronounced good-doe

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

      like robot, ask the godot authors

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

    guys sorry but after long time search i found how i do it thnx anyway

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

    in Godot 4.0:
    .instance(), is instantiate()

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

    12th!!! YAY.. lol. Saw the tweets. Gotta love the insta dislikes!

    • @michaelcapone175
      @michaelcapone175 8 ปีที่แล้ว

      +Sayado -MC I think some people were upset when there was a Godot tutorial instead of a GameMaker RPG Basics tutorial posted. I do not agree with that, but that is why I think there are some instant dislikes.

    • @SayadoMC
      @SayadoMC 8 ปีที่แล้ว

      +Michael Capone, yea lol. He tweeted about it to rm2kdev and Shaun Spalding. Funniest. Thing. Ever

  • @Zero-4793
    @Zero-4793 4 ปีที่แล้ว

    This episode frustrated me a little as you kept derailing and postponing, took me a while to get everything working this time.

  • @NikolajLepka
    @NikolajLepka 6 ปีที่แล้ว

    please for the love of sanity, put spaces around your operators

    • @uheartbeast
      @uheartbeast  6 ปีที่แล้ว

      Haha you are very passionate about that it seems.

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

    Benjamin is not a bad lookin fella

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

    God, it's not "Ancor", it's "Anchor". Literally unwatchable :P
    Nice tutorial BTW, even though I don't really like this Godot thing.

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

      +Arkadiusz Jagiełło LOL! Learning Portuguese has destroyed my English XD Oh well.

    • @HiroshiMorenos
      @HiroshiMorenos 6 ปีที่แล้ว

      Como vai o seu português? Fiquei curioso 😉

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

      I just assumed that was how Americans spelled it :P