• 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!

2D "height" collisions?

D

DevNorway

Guest
What's the basic idea behind having collisions based on your "height"?
Code:
// horizontal collision
if place_meeting(x + hsp * spd, y, obj_collision) {
    x -= hsp * spd;
}
x += hsp * spd * !attacking;

// vertical collision
if place_meeting(x, y + vsp * spd, obj_collision) {
    y -= vsp * spd;
}
y += vsp * spd * !attacking;

What I want, is a collision that is determined by what your current height is. How would I go about this?
 

Tthecreator

Your Creator!
Well, your 2 objects will have 2 y coordinates. What you could do is when moving close to an object is checking the y coordinates before walking, and after walking. Then if the y of the object and the player are different then you place the player back at the position closest to that object.
There are a lot of other ways to do this though, and I'd suggest looking up some collision tutorials. Even if they don't work in the exact way you want them to, you can still learn a lot from them and if you truly understand those tutorials then you should be able to make that code your own.
 
Top