This site requires JavaScript, please enable it in your browser!
Greenfoot back
darkmist255
darkmist255 wrote ...

2012/5/11

Is there something about getOneIntersectingObject() that I don't understand?

darkmist255 darkmist255

2012/5/11

#
Alright, I'm having a strange bug that I can't seem to figure out even what the cause of it is, let alone a solution. I've narrowed it down to what I think might be a cause. I'll describe the bug as well as I can: The player is "standing" on a block, but he is actually about 5 pixels into the block. The method below (which runs every act cycle) seems to return "falling = true" when the player is only about 3-4 pixels submerged, sending him back down to about 5 pixels (I don't know the actual numbers for any of this, that's just the appearance). I've tried playing around with almost everything but nothing seems to have a positive effect. PS: I have changed the gravity move speed from 0.1 (double based movement, I'm 100% positive it's not a factor) to 2 and noticed no difference.
        falling = false;
        
        standingOnBlock = true;
        standingOnLadder = true;
        
        int horizRadius = (getImage().getWidth() / 2);
        int vertRadius = (getImage().getWidth() / 2) + 1;
        if(getOneObjectAtOffset(horizRadius, vertRadius, Block.class) == null && getOneObjectAtOffset(-horizRadius, vertRadius, Block.class) == null && getOneObjectAtOffset(0, vertRadius, Block.class) == null)
        {
            standingOnBlock = false;
        }
        if(getOneObjectAtOffset(horizRadius, vertRadius, Ladder.class) == null && getOneObjectAtOffset(-horizRadius, vertRadius, Ladder.class) == null && getOneObjectAtOffset(0, vertRadius, Ladder.class) == null)
        {
            standingOnLadder = false;
        }
        
        if(!standingOnBlock && !standingOnLadder)
        {
            falling = true;
        }
kiarocks kiarocks

2012/5/11

#
Remember, getOneObjectAtOffset does not take the image into account.
davmac davmac

2012/5/11

#
What do you mean by that kiarocks? darkmist255, you seem to have a mistake on line 07. You are using getWidth() where I assume you meant to use getHeight().
darkmist255 darkmist255

2012/5/12

#
Wow... Thanks davmac, I can't believe I didn't notice that! That would explain the character sinking into the ground since he's taller than he is wide... Well I think from now on I'm not just going look for what might be wrong with how I'm doing it, I'll look for typos first :D!
You need to login to post a reply.