1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

bouncing objects

Discussion in 'Programming' started by pgvago, May 14, 2019 at 10:17 PM.

  1. pgvago

    pgvago Member

    Joined:
    Tuesday
    Posts:
    9
    hello from italy (again);

    can i anybody suggest an idea on how you would make an object bounce off a wall.
    the antifairy in zelda is ideally what i am trying to achieve.



    please move to 03:02.

    i would love a suggestion on how you would tackle the problem.

    thanks, pietro.
     
  2. Gzebra

    Gzebra Member

    Joined:
    Aug 3, 2017
    Posts:
    63
    use speed and direction for movement, and randomly add or subtract 90 to direction when the object collide with the wall.
     
  3. Timothy

    Timothy Member

    Joined:
    Aug 7, 2016
    Posts:
    59
    Except it's not random.

    Simple solution.
    If colliding on x axis, reverse hspeed.
    If colliding on y axis, reverse vspeed.
     
  4. pgvago

    pgvago Member

    Joined:
    Tuesday
    Posts:
    9
    thank you for your replies.
    let me do some experiments on your suggestions and i'll get back to you.

    pietro.
     
  5. pgvago

    pgvago Member

    Joined:
    Tuesday
    Posts:
    9
    how can i check if i am colliding on the x or y axis?

    thanks, pietro.
     
  6. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    918
    Two collision checks. One for the x axis plus hspeed, one for the y axis plus vspeed. Whichever returns the hit, reverse the appropriate variable.
     
  7. pgvago

    pgvago Member

    Joined:
    Tuesday
    Posts:
    9
    can i please ask you for a couple lines of code?

    pietro.
     
  8. Rattlejaw

    Rattlejaw Member

    Joined:
    Jun 24, 2017
    Posts:
    6
    You can try this. It's a very simple method.

    In the object that is bouncing off walls.

    CREATE EVENT
    direction = (random_range(45,135));
    speed = 2;

    Add a collision event with your obj_wall. In that event, use the following function.

    move_bounce_all(true);

    The object should move around and bounce off of walls. You can change the values in the direction and speed to tweak it. If you don't want it's starting direction to be so random, you can just have direction = 45 or something like that.

    Where ever you place or spawn the object in the room, it does effect it's moving pattern.
     
    Last edited: May 18, 2019 at 3:06 AM
  9. pgvago

    pgvago Member

    Joined:
    Tuesday
    Posts:
    9
    thanks for your help.
    unfortunately there isn't much literature on move_bounce_all ().

    does the object bounce bounce at the same angle?

    thanks, pietro.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice