GMS 2 Collision Not Working Correctly

Discussion in 'Programming' started by Dark Pyro, Jan 11, 2019.

  1. Dark Pyro

    Dark Pyro Member

    Joined:
    Nov 30, 2018
    Posts:
    28
    Hey guys!

    Hope you're having a great year so far!
    But... I have a question, eheheh

    So, I'm currently developing this mini-game where you have a ball that bounces on platforms that keep on falling. I have limited the play area but a problem keeps popping up.

    So my idea was, as soon as the player object touched the platform, the player would jump for a certain height and then fall down, and so on... Now, this is working kinda correct.
    The player sprite slips through the platform just a bit, and then jumps when it should be pixel perfect collision.

    But my main question problem is:

    If the player jumps and collides with a platform, it freezes in that position, the platform keeps falling down and just as the platform completely passed through the player, he jumps... Obviously this wasn't intended but I'm not able to fix that, although I tried with a few diferent ways and functions.

    Any help?

    I'll leave some code here and a picture of this event.

    --|| oPlayer Step Event ||--

    Code:
    #region //Reset Jump
    
    if(place_meeting(x, y + 1, oPlatform)){
        canJump = true;
    }
    
    #endregion
    
    #region //Movement and Platform Collision
    
    if(place_meeting(x + hSpeed, y, oPlatform)){
        while(!place_meeting(x + sign(hSpeed), y, oPlatform)){
            x += sign(hSpeed);
        }
        hSpeed = 0;
    }
     
    if(instance_place(x , y + oPlatform.spd, oPlatform) != noone){
        vSpeed = 0;
    }
    
    x += hSpeed;
    y += vSpeed;
    --|| oPlatform Step Event ||--

    Code:
    y += spd;
     

    Attached Files:

  2. Desix

    Desix Member

    Joined:
    Jun 23, 2016
    Posts:
    427
    At a glance it's probably because you have instance_place there for y collision and if it's true vSpeed is set to 0. so the platform would have to move out the way before vSpeed isn't being set to 0 any more. Also, it'll have to wait even longer since you're checking at y+oPlatform.spd
     
    Dark Pyro likes this.
  3. Dark Pyro

    Dark Pyro Member

    Joined:
    Nov 30, 2018
    Posts:
    28
    Thanks for the answer!!!

    That makes sense, I actually thought about it...
    Is there a function to fix this problem?

    Thank you again
     
  4. Desix

    Desix Member

    Joined:
    Jun 23, 2016
    Posts:
    427
    There's no auto fox, you just have to change your approach. Couple ideas for your current method though:

    You could only check for a bounce if the ball is moving downwards (when it bounces, make it move up and it'll no longer check for the platform)
    Or you could have a variable which is set to the ID of the block you just bounced on, then if it finds that ID again it will ignore it.
     
  5. Dark Pyro

    Dark Pyro Member

    Joined:
    Nov 30, 2018
    Posts:
    28
    Thank you for the sugggestions!!

    The first one is the best aproach although not exactly what I wanted...

    But I will try that approach, I will post the results here

    Thank you for the advise! ^^
     

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