Bounce Touch 2d

broken image

= new Vector2(newWorldPosition.x, newWorldPosition.y) Vector3 newWorldPosition = (screenPosition) A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. In this example, the script will check if the ball goes of screen, and if it does, clamps the position between the screen edges and changes the velocity so the ball will bounce to the opposite direction. Note in the GIF below that if I change the aspect ratio, the ball still bounces when touching the edges.

broken image