Wednesday 18 September 2013

How do you make an object move opposite direction?

How do you make an object move opposite direction?

I need to make a boat move in its opposite direction when it hits out of
bounds (8, -8).
The boat moves but adding its current velocity to its current position. If
the boat hits a boundary it turns around and moves in the opp.
direction...
}
public void move(int direction)
{
this.position = position + direction;
this.velocity = velocity + position;
if ( position > 5)
{
direction = - 1;
}
else if ( position < -5)
{
direction = + 1;
}
}
}
It does not work.. Any help would be great.
Thank you :)

No comments:

Post a Comment