- Home /
How do I make an object bounce around the camera edge?
My ship spawns power-ups and I want the power-ups to stay in the screen, so I want them to be bounce on the camera so as my player moves around the map, the power-ups are around him and not left behind.
Please help!
Answer by BeardOfFury · Nov 11, 2013 at 10:38 PM
If your camera size isn't going to change and the camera is orthographic then you can place colliders on the edges of the field of a view, and them make them children of the camera itself (just in case the camera happens to move around in the x and y axis). If you only want power ups to bounce of these colliders you can setup their layers(on both to powerups and colliders) and make sure only the powerups can interact with the colliders.
The camera moves along the player... and how do I even write a bouncing script?
But the camera size is the same? It doesn't zoom in and out? As for the bouncing you can add a physics material to your powerups or colliders so it bounces off the colliders. So they'll naturally bounce using the physics engine.
As for how you want them to move that's a different question. If you want them to bounce around all Pong style then you'll want to detect OnCollisionEnter on the powerup and apply a force or something or a script that makes sure that the magnitude of the rigidbody's velocity (while not in a collision) is constant.