Hello,
I am stuck with making an actor bounce when it encounters a wall or atWorldEdge()
It seems that the answer to this is so obvious, yet I can not get to it...
Here is the code to it:
And the code for the vector:
The problem with this is that when the getRotation() of the actor is 90 degrees for example, if I go forward, it bounces back, which is correct.
However, if I go backwards (with the getRotation() of the actor still being 90 degrees, instead of bouncing forward, it goes back.
I know that in terms of code, it's acting accordingly, so the code is right for how it acts, but not right for how it is intended to act.
Can anybody please help me set the bounce = new Vector to act as intended?
Thanks in advance!
private void checkCollision()
{
Actor Connector = getOneIntersectingObject(Connector.class);
Vector bounce = new Vector(getRotation()-180, 0.5);
if (Connector != null)
{
//accelerate(0.8); //walk slower
//or
//stop();
//or
addForce(bounce);
}
if(atWorldEdge())
{
//stop();
addForce(bounce);
}
} public Vector(int direction, double length)
{
this.length = length;
this.direction = direction;
updateCartesian();
}

