GMS 2 [SOLVED] Getting bbox_bottom of a collided object

Discussion in 'Programming' started by Raff, Dec 6, 2018.

  1. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    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 !!!
     
  2. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    57
    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
     
  3. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    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.
     
  4. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    57
    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?
     
  5. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    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.
     
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    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;
     
  7. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    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.
     
  8. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    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.
     
  9. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    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.
     
  10. Raff

    Raff Member

    Joined:
    Feb 28, 2018
    Posts:
    33
    Done!!, finally it works, thankyou everybody for your time.
     

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