First of - I'm pretty new to Greenfoot, so I'm very sorry if I can't understand everything, but I'll still try to follow!
I've added collision to an object (a wall), so the actor can't run through it. It works fine, but everytime I want him to turn around and move in a different direction, he jumps through the wall and gets stuck behind it. I've tried to find a solution in some of the older discussions, but I wasn't able to find anything, so I'd be glad if anyone could help me with it.
The wall is called "BF_MCHouseWalls_East"
This line defines the speed
This is one of my "move()" lines (there are a few more)
and this is the questionable line that makes the collision possible:
and this is the integration of the "collision-line" into the act-method
I hope all of this is enough information to understand what I want my actor to do, and I hope someone is able to find the mistake in it. Thanks!
private int speed = 3;
/**
* moveUp - MC geht nach oben
*/
public void moveUp()
{
move(speed);
setRotation(270);
}
/**
* MC prüft ob Mauer vorhanden
*/
public void checkWall()
{
if(getOneIntersectingObject(BF_MCHouseWalls_East.class) != null)
{
move(-speed);
}
}
/**
* Act
*/
public void act()
{
basicMovement();
checkWall();
}
