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

2012/7/8

Need help with collision in orbworld

cyberfletch cyberfletch

2012/7/8

#
Have been trying to get orbs to collide but still pass right threw each other. public Velocity getVelocity() { return vel; } public Orb getIntersectingOrb() { Actor a = getOneIntersectingObject(Orb.class); if( a!= null) { return (Orb)a; } else { return null; } } public Orb handleOrbCollision() { return null; } public void setVelocity(Velocity newVel) { vel = newVel;
SPower SPower

2012/7/8

#
A tip for posting comments with code inside: press the code button under the text field, and enter your code there. In your act method, you can do this:
if (getIntersectingOrb() != null) {
   // we hit a ball! Now, let's bounce.
}
And to make your code cleaner, you can just change the getIntersectingOrb() method to this:
return (Orb) getOneIntersectingObject(Orb.class);
Because you can return null, directly, so the if statement isn't useful, but the result will be the same.
You need to login to post a reply.