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

2019/1/31

Actors pass through walls

Aftermath Aftermath

2019/1/31

#
 public void movement(String left, String right, String up, String down, int speed, int turnspeed) //#The variables can be changed dependent on the user input on the players.
    {
        if (Greenfoot.isKeyDown(left)){ //#When the variable for left is placed it starts this statement.
            turn(-turnspeed); //#Moves at set speed from the varialbe.
        }
        if (Greenfoot.isKeyDown(right)){ //#When the variable for right is placed it starts this statement.
            turn(turnspeed); //#Moves at set speed from the varialbe.
        }
        if (Greenfoot.isKeyDown(down)){ //#When the variable for down is placed it starts this statement.
            if (this.isTouching(Wall.class)){ //#If touching the wall does this segment.
                move(speed); //#Moves 0

            }   else { //#If not touching wall does this segment.
                move(-speed); //#Moves at set speed from the varialbe.
            }
        }
        if (Greenfoot.isKeyDown(up)){ //#If deisgnated button pressed (W or Up) if starts.
            if (this.isTouching(Wall.class)){ //#If touching the wall does this segment.
                move(-speed); //#Moves -5

            }   else { //#If not touching wall does this segment.
                move(speed); //#Moves at set speed from the varialbe.
            }
        }
    }
Aftermath Aftermath

2019/1/31

#
I did comment on this, but when the actor hits the wall it will not go through it, but when it starts to reverse, or faces the other way and drives forward, it goes through the walls as if it was driving normally.
danpost danpost

2019/1/31

#
Aftermath wrote...
I did comment on this, but when the actor hits the wall it will not go through it, but when it starts to reverse, or faces the other way and drives forward, it goes through the walls as if it was driving normally.
It is best to first do an action (turn or move), then check for an obstacle. If one is encountered, then undo the action. That way, you are always not over an obstacle after each act step.
Aftermath Aftermath

2019/2/6

#
danpost wrote...
Aftermath wrote...
I did comment on this, but when the actor hits the wall it will not go through it, but when it starts to reverse, or faces the other way and drives forward, it goes through the walls as if it was driving normally.
It is best to first do an action (turn or move), then check for an obstacle. If one is encountered, then undo the action. That way, you are always not over an obstacle after each act step.
Thank you, this fixed it.
You need to login to post a reply.