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

2016/3/23

Bullets kill the object before hiting it

MrSandwich MrSandwich

2016/3/23

#
I have one problem when firing bullets with the intention of removing a certain object, but the bullet removes the object way before it even hits the object in question. My code is currently like this ( in the object I want to remove class):
 public void die()
    {
        Actor bullet = getOneIntersectingObject(Bullet.class); 
        
        if(bullet != null)
        {
            getWorld().removeObject(bullet);
            getWorld().removeObject(this);
        }
    }
should i code it in a different way? Appreciate all the help
danpost danpost

2016/3/23

#
You may have excessive transparency around the image of the actor detecting the bullet. All parts of the image are included in the intersection of actors.
MrSandwich MrSandwich

2016/3/24

#
How do I check this? I made sure to crop the image, so it has no additional spaces I do not intend to have.
danpost danpost

2016/3/24

#
I wrote an Image Transparency Adder/Trimmer scenario that you can download and run to select an image and remove any excess transparency. Make sure to make a copy of the image file as a backup before using the scenario (at least until you get used to how the scenario works).
MrSandwich MrSandwich

2016/3/24

#
Thank you very much, will try it asap. And post back the results and any doubts I might find. EDIT: It's working now!! Thank you for doing what you do and for all the help :)
You need to login to post a reply.