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

2012/5/24

bouncing of walls

tylers tylers

2012/5/24

#
why don't this work? it works fine on the top and bottom walls but not the sides.
if(getY() <= 5 || getY() >= getWorld().getHeight() -5)
        {
            setRotation(360-getRotation());
        }
       
        if(getX() <= 5 || getX() >= getWorld().getWidth() -5)
        {
            
            setRotation(360-getRotation());
        }
dlanni dlanni

2012/5/24

#
I had a similar problem recently and the solution was to use 'if getX( ) =0' for the left side and 'getWidth() - 1' for the right side. I'm just a beginner, but maybe this will help.
danpost danpost

2012/5/24

#
For the side walls, try:
setRotation(540 - getRotation());
If it comes back OutOfBoundsException, use:
setRotation((540 - getRotation()) % 360);
tylers tylers

2012/5/24

#
thanks danpost, the first code worked also, thanks dlanni.
tylers tylers

2012/5/24

#
how do i stop it from bouncing from one wall to another in the same place fixed it
You need to login to post a reply.