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

2018/12/4

how do i make my hit detection better?

zach0531 zach0531

2018/12/4

#
I am making a space invaders game and the alien bullets only hit the space ship if the bullet hits it in the dead center. I want the to make the ship have a better hit detection so the bullets don't pass through the ship.
nolttr21 nolttr21

2018/12/5

#
Are you using the isTouching method or the GetOneObjectAtOffset method?
zach0531 zach0531

2018/12/5

#
Getoneobject at offset. I will try the other.
zach0531 zach0531

2018/12/5

#
this is my hit code under the space ship. it is still not working
 public void hit() 
    {
        Actor Bullet2;
        Bullet2 = isTouching (0, 0, bullet2.class);
        if (Bullet2 != null)
        {
            World world;
            world = getWorld();
            world.removeObject(Bullet2);
            ((space)world).healthbar.add(-50);
        }  
    }
danpost danpost

2018/12/5

#
zach0531 wrote...
this is my hit code under the space ship. it is still not working << Code Omitted >>
The isTouching method returns a boolean value -- not an Actor object. Try
public void hit()
{
    if (isTouching(bullet2.class))
    {
        removeTouching(bullet2.class);
        ((space)getWorld()).healthbar.add(-50);
    }
}
You need to login to post a reply.