- Home /
What's a good way at keeping a ball bounce around inside the scene?
Total newbie at Unity here. I'm trying to have a ball bounce around while following the player. While I've accomplished that, I'm trying to keep the ball within the player view as the player moves around the level.
I tried attaching box colliders set up around the camera, and while it does work in keeping the ball in player view, it won't let any objects with rigidbodies outside the camera enter the scene view anymore.
Is there any better way in keeping the ball bouncing around while keeping it inside the camera? Thanks.
Answer by GeoJaxon · Jan 16, 2021 at 07:16 AM
Sounds like you have some problem-solving to do! I think you have an alright solution actually, maybe you can use a tag or layer so that objects can differentiate between those colliders and others? Or maybe a trigger area that reverses the ball's velocity in x and z directions, so that objects can still move in and out of the camera? Also if you can have a reference to the main camera, perhaps you can find a way to use its field of view to calculate exactly when to reverse x and z velocities of the ball so that it bounces back into the scene.
I completely overlooked layers! After adding in some layers for the ball, player and camera and switching up how all the layers collide, I was able to get what I wanted. Thank you so much!!
Your answer
Follow this Question
Related Questions
2D Physics Problem? 1 Answer
Character input works but gets dragged back for no reason 1 Answer
Unity 2d Physics Collision Jumping / Glitching 0 Answers
How can I make two objects with rigid bodies that won't displace each other? 2 Answers
Rigidbody2D is kind of flying instead of falling when the child box is colliding 1 Answer