Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void HitWall(Collision2D collision)
- {
- // We don't want the reflect to decide the x direction.
- // Store the current direction.
- var direction = desiredVelocity.x;
- // Get the surface we contacted.
- ContactPoint2D contact = collision.GetContact(0);
- // DesiredVelocity is a variable defined at the top of the class. It is used to keep track of the desiredDirection, and speed.
- // Figure out the new y trajectory.
- desiredVelocity = Vector2.Reflect(desiredVelocity, contact.normal);
- // Set x back to the stored direction.
- desiredVelocity.x = direction;
- // Use the new desiredVelocity to adjust the rigidbody velocity.
- AdjustVelocity();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement