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

2017/1/5

stop when wall

iiuulliiaannaa iiuulliiaannaa

2017/1/5

#
Hei I have a ball bouncing between 2 objects and when the ball is not touching one of them is going obviously out in the wall but is not stoping there and come back to the player is moving until the corner and then stuck there and the score remains 0 always Should I create walls around to have the intersection ?!Or ?! I am just driving crazy :(( Am I clear ?
danpost danpost

2017/1/5

#
First, you can remove the following lines as they do not really do much at all:
Actor net = getOneIntersectingObject(barrier.class);
if (net!=null)
{
    turn(0); // no effect
    move(1); // only makes the ball go slightly faster when over the barrier
}
I do not think the barrier would cause the ball to go faster when near it and going faster for a short time without any cause would defy physics. Now, there are four edges (please do not call them walls) of the world -- two sets, one horizontal and one vertical. Each set changes the movement along its opposing axis (horizontal edges changes the vertical movement of the ball and vertical edges change the horizontal movement). Therefore:
// vertical edges changing horizontal movement
if (getX() == 0 || getX() == getWorld().getWidth()-1) setRotation(180-getRotation());
// horizontal edges changing vertical movement
if (getY() == 0 || getY() == getWorld().getHeight()-1) setRotation(360-getRotation());
You need to login to post a reply.