• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Collision Not Working Correctly

D

Dark Pyro

Guest
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;
 

Attachments

DesArts

Member
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
 
D

Dark Pyro

Guest
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
Thanks for the answer!!!

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

Thank you again
 

DesArts

Member
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.
 
D

Dark Pyro

Guest
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.
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! ^^
 
Top