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

2013/10/30

collision of more than one object at a time.

i_joker123 i_joker123

2013/10/30

#
im trying to implement a collision method where more than one bullet can collide with loads of baddies at the same time. So far my collision works, but when i fire a few bullets i get the following error: java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:663) at greenfoot.Actor.getOneIntersectingObject(Actor.java:912) at bullet.collision(bullet.java:33) at bullet.act(bullet.java:22) at greenfoot.core.Simulation.actActor(Simulation.java:568) at greenfoot.core.Simulation.runOneLoop(Simulation.java:526) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) Heres my bullet class: public class bullet extends Actor { public void act() { move(5); collision(); } public bullet(int direction) { setRotation(direction); } private void collision() { Actor baddie=getOneIntersectingObject(Baddie.class); if(baddie !=null) { getWorld().removeObject(baddie); getWorld().removeObject(this); } } } Any suggestions? Thanks in advance!
danpost danpost

2013/10/30

#
Is the 'move' method being called the one in the Actor class or has it been overridden in this class (if it has been overridden, please show its code).
i_joker123 i_joker123

2013/10/30

#
public class baddie extends Actor { /** * Act - do whatever the arrow wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private int speed; public void act() { // Add your action code here. MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse !=null) setRotation((int)(180*Math.atan2(mouse.getY()-getY(),mouse.getX()-getX())/Math.PI)); move(speed); if(Greenfoot.mouseClicked(null)) { getWorld().addObject(new Bullet(getRotation()),getX(),getY()); turnTowards(mouse.getX(), mouse.getY()); } }
You need to login to post a reply.