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

2019/4/4

How to make bullet collision detection?

MrMinestrone MrMinestrone

2019/4/4

#
I am trying to make a game where if 2 bullets crash they will both get deleted. However this is not the case with my code. Sometimes one gets deleted and sometimes the other one does. How can I fix this?
if (isTouching(Bullet2.class))
        {
            getWorld().removeObject(this);
        }
and on the other one
        if (isTouching(Bullet1.class))
        {
            getWorld().removeObject(this);
        }
AndreaSantana AndreaSantana

2019/4/4

#
maybe you can change a isTouching to new syntax getOneIntersectingObject(Bullet1.class)
danpost danpost

2019/4/4

#
You need to delete both bullets in both case because only one will detect the collision if deleting either.
MrMinestrone MrMinestrone

2019/4/4

#
danpost wrote...
You need to delete both bullets in both case because only one will detect the collision if deleting either.
How do you do that?
danpost danpost

2019/4/5

#
MrMinestrone wrote...
How do you do that?
Use the removeTouching method. Put it first as 'this' actor needs to still be in the world for that method to work.
MrMinestrone MrMinestrone

2019/4/5

#
danpost wrote...
MrMinestrone wrote...
How do you do that?
Use the removeTouching method. Put it first as 'this' actor needs to still be in the world for that method to work.
Ok, thanks
You need to login to post a reply.