- Home /
move 2D object in opposite direction after collision
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
Answer by Ninjapro2k_ · Jan 02, 2017 at 04:25 AM
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 :)
Your answer
Follow this Question
Related Questions
Moving a ball in the opposite direction of where it hits 1 Answer
Unity 2D - How do I add the velocity and direction of an object to another object? 2 Answers
Sword slashing logic on Gear VR using controller? 0 Answers
Collider question 0 Answers
Rigidbody magnitude comparison is not working correctlly? 2 Answers