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

2013/4/23

Beam Intersects object

How would I make danposts flashlight beam figure out when the light is intersecting an object. That's the only problem I've found with the Beam Actor, is that the darkness is part of the beam, causing it that intersecting objects would anything around the source. I think I would have to do something with the rotation of the light, but I can't seem to figure out how to do it.
Never mind, I figured it out. Here's the code if interested:
Slender s = (Slender)getObjectsInRange(400, Slender.class).get(0);
        int sX = s.getX();
        int sY = s.getY();
        int dir = getRotation();
        turnTowards(sX, sY);
        int dir2 = getRotation();
        setRotation(dir);
        return dir - dir2 <= 20 && dir - dir2 >= -20;
You need to login to post a reply.