I have a 2D sprite object. I want it to move non-stop with a certain speed. After a collision with one of the four boundaries, it should move in opposite direction with same angle (>). for example, if the ball hit a wall with 45 angle, it should be bounced in opposite direction with same angle. Ball should always be moving. Thanks
In a case where you’re telling the object to move forward- relative to the object’s orientation-, rather than specifically left of right: You could call OnTriggerEnter2D and flip the object, so it would continue moving forward relative to it’s rotation.
void Flip()
{
isFacingRight = !isFacingRight;
Vector2 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
You could also use Rigidbody2D.AddForce ![]()