Hi, I've been having some trouble finding a way to remove both a bullet and the actor if the bullet hits an actor.
public void act()
{
move(100); //This should just be the bullet movement code
checkForPlayer();
}
public void checkForPlayer()
{
if (getOneIntersectingObject(Player.class) != null)
{
getWorld().removeObject(getOneIntersectingObject(Player.class));
getWorld().removeObject(this);
}
}public void checkForPlayer()
{
if (isTouching(Player.class))
{
removeTouching(Player.class);
getWorld().removeObject(this);
}
}public void act()
{
move(100);
checkForHit();
}
private void checkForHit()
{
if (atWorldEdge())
{
getWorld().removeObject(this);
}
if (isTouching(Alien1.class))
{
counter.add(1);
removeTouching(Alien1.class);
getWorld().removeObject(this);
}
if (isTouching(Alien2.class))
{
counter.add(5);
removeTouching(Alien2.class);
getWorld().removeObject(this);
}
}