• 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 [SOLVED] Getting bbox_bottom of a collided object

R

Raff

Guest
Hello everybody,

How can i get working this:

Code:
if(instance_place(x, y, ob_block))
{
     var inst = instance_nearest(x, y, ob_block);
     col2 = sprite_get_bbox_top(object_get_sprite(inst));
}
Because col2 returns "-1" when collision.

I already tried it with "instance_position" too.

I want to have a one way collision object, and i have it working, but some times, when i jump from a concrete position, the player gets stuck in the middle of the object instead of on top. So i want to have the bbox_top of that object to try the collision just with the top of it.

Thankyou very much !!!
 

Ido-f

Member
you can do

Code:
var inst = instance_place(x, y, obj_block)
if (inst != noone)
{
and then access the bbox information like so: inst.bbox_top
 
R

Raff

Guest
Thankyou, it works, but now, i can't have the rest of the code working.

Anyway, do you know how to have one way object platform collision working with any kind of stuck, please ? because i have it working except from a concrete position, from where, if the the player jumps, it stucks in the middle of the platform when landing.
 

Ido-f

Member
Personally I've never implemented one way object collisions, only with grid collisions.
I suggest you look it up online, as there are plenty of threads and videos on the subject.
You could also try to solve it by yourself for practice.

What did you mean by jumping from a concrete position, by the way?
 
R

Raff

Guest
I have it working but if i jump from a concrete distance from the platform, the player stucks in the middle of the platform instead of fall through it.
 

TheouAegis

Member
What's the code you're actually using? sprite_get_bbox_top() is pretty useless, since all it tells you is the y-coordinate of the top bounds of the sprite resource. Typically you want to use the variable bbox_top, which is the top of the bounding box of the instance in the room.

var col2;
with instance_place(x,y,boj_block) col2 = bbox_top;

Or if col2 is a permanent variable in your player:

with instance_place(x,y,obj_block) other.col2 = bbox_top;
 
R

Raff

Guest
Thanks for your answer,

i tried this:
Code:
var col = instance_position(x, bbox_bottom+moveY, ob_block);
with(col) col2 = bbox_top;
               
if(col)
{
    while(bbox_bottom < col2)
    {
        y += sign(moveY);
    }
    moveY = 0;
}
But it works the same way. the player stucks in the middle of the platform if i jump from the same place.
 

TheouAegis

Member
Code:
if moveY > 0
{
   with instance_position(x,bbox_bottom+moveY, ob_block)
   {
      other.y += bbox_top - other.bbox_bottom;
      other.moveY = 0;
   }
}
I'm guessing your issue is maybe you have code elsewhere, such as gravity code, resetting moveY and so you stop upon collision but then fall back down.

If it's a moving platform, the platform could be moving up into the player, too. The way I handle moving platforms personally is to store the platform's id in the player when he collides with it and then in the End Step event snap the player to the platform like I did here.
 
R

Raff

Guest
Ah, ok, thankyou. i will try something when come back from work. I have the code in the player step event, will see what can do later, thankyou again.
 
Top