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

2014/5/2

How does one make an actor move when another actor comes in contact with it?

Arichman Arichman

2014/5/2

#
I have an actor called "Robot". I want an actor called "Red_Ball" to move when Robot touches it. If anyone knows how that would work please answer. I'd be happy to post code for the stuff if it is necessary. -Thank you
danpost danpost

2014/5/2

#
Be more specific as to how you want the ball to move, if touched; and post what code you have tried. I mean, you could put:
if (isTouching(Robot.class)) move(1);
in the act method of the class of the red ball; but, I am sure that is not what you want.
Arichman Arichman

2014/5/6

#
Here is the code for the Red_Ball:
public class Red_Ball extends Actor
{
    public void act() 
    {
        if (isTouching(Robot.class)) move(1); 
    }
}
Here is the code for the Robot:
public class Robot extends Actor
{
    public void act() 
    {
        MoveAround();
    }    
    
    public void MoveAround()
    {
        if (Greenfoot.isKeyDown("a"))
           turn(-3);
        if (Greenfoot.isKeyDown("d"))
            turn(3);
        if (Greenfoot.isKeyDown("w"))
            move(3);
        if (Greenfoot.isKeyDown("s"))
            move(-3);
    }
}
The code there was definitely a start :)
You need to login to post a reply.