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

2015/4/25

Greenfoot Hitbox

craeXD craeXD

2015/4/25

#
Good Morning, i have a problem and i can´t solve it on my own. I found nothing about this topic. I have a little programm, where a player should kill zombies an other monsters. This is working quite good, but the hitbox isn´t always perfect. For example: My boss is a spider an i can only hit the body-part, not the legs. If i put the image in another class (wall for example) it the shots hit to early.
public P9mm()
    {
        P9mmschauzuMaus();
        image1 = new GreenfootImage("bullet.png");
        setImage(image1);
    }
    

    public void act() 
    {
     move(15); /*Geschwindigkeit Kugel*/
     
     Actor Wand = this.getOneObjectAtOffset(15,15, Wand.class);
     if(Wand != null)
     {
         getWorld().removeObject(this); 
     }
     else if(hitEdge())
     {
         World w = getWorld();
         w.removeObject(this);
     }
    }
public int HP = 50; 
    /*Lebensabzug für P9mm*/            public int DmgP9 = 1;

public void Health()
   {
       Actor P9mm = this.getOneIntersectingObject(P9mm.class);
       
       if(P9mm != null)
       {
           if(HP >= 0)
           {
             getWorld().removeObject(P9mm);
             
             HP = HP - DmgP9;
             
                if(HP <= 0)
                {
                 Greenfoot.playSound("slurp.wav");
                 getWorld().removeObject(this);
                }
           }
       }
       
   }
With this code it also hits to early. I also tried "Actor P9mm = this.getOneObjectAtOffset(15,15, P9mm.class);". Obviously not successfully. With this code it hits to late. mfg, alex
craeXD craeXD

2015/4/25

#
No one? No idea? The only workaround i know is to make the image bigger, well not really bigger, but more free space between the real picture an the edge. mfg, alex
danpost danpost

2015/4/25

#
If you have excess transparencies in your images, you could try running your images through my Image Transparency Adder/Trimmer scenario. Download it; open it; save it as a 'jar' file (or not); then use it to remove excess transparencies from around your images. After running your images through it, the 'getIntersectingObject' method may be good enough. If not, another option might be to look for the bullet from the P9mm class instead of looking for spider from the Bullet class. You might be able to find a decent range to look in (using 'getObjectsInRange' or 'getNeighbours') that would work closer to what you want. 'getObjectsInRange' will look in a circle shaped area around your actor 'getNeighbours' with 'false' on stepping diagonally will look in a diamond shaped area around your actor 'getNeighbours' with 'true' on stepping diagonally will look in a square shaped area around your actor
craeXD craeXD

2015/4/26

#
Don´t work. The problem are not the images, i removed the excess transparencies whit gimp. This makes no differenc. With "getOneIntersectingObject" it hits only the body-part, not the legs of my spider boss and with "getOneObjectAtOffset" it hits the air in front of the spider...i think because its the edge of the image - no difference if its transparent or not. It tried the "getObjectsInRange"-command serveral times, in different variations and classes - nothing works. Either there is a error message (cant given types) or it simply doesn´t work. What am I doing wrong? I just want a circle/field around my Boss.class (not actor), where the bullet (P9mm) hits. Not only the body-part of it.
danpost danpost

2015/4/26

#
craeXD wrote...
What am I doing wrong? I just want a circle/field around my Boss.class (not actor), where the bullet (P9mm) hits. Not only the body-part of it.
For a circle/field, use the 'getObjectsInRange' method. For around your Boss.class, code it in the Boss class. For bullet hits, look for Bullet.class.
You need to login to post a reply.