

You may notice that the “use gravity” parameter of this component is checked by default, which will add gravity to this game object, and therefore it will drop onto the plane. Make sure the Position and Rotation Parameters of the Transform component in the Inspector menu (Red box in the figure below) are all set to zero:ĭoing so will add a Rigidbody component to the ball game object. To add the floor, in the Unity editor, go to the GameObject menu on top, then 3D Object -> Plane. The scene should be already open and ready. To achieve this, we will use the default empty scene that comes with every new unity project. the box) in which we will be moving the ball.

Name your project “Roll the ball” and make sure the template is set to “3D”.īefore beginning the programming of the game behaviors described above, we need to set up the play area (i.e. Create a new project (you should already know the steps from the previous sections). Close your unity editor and open the Unity Hub.The following steps will help you to first conceptualize what needs to be implemented and how it should be done, and second, guide you on how to utilize the Unit圓D game engine to realize the needed game objects, mechanics, and functionalities. Each time the ball hits a coin one point should be awarded to the player, a “cashier” sound effect played, and then that coin should disappear from the scene (i.e. The coins should simulate a rotation animation, capturing the attention of the player. The slower speed for the ball is necessary for my game, and I would really appreciate it if I could get some help on this issue.The objective of the game is to roll a ball inside a box and collect all the available coins. Note: This code is inside a custom class (inherits MonoBehavior) I made for the ball object to manage the physics actions.įor additional information, refer to this video to see how the game responds. Here is some of the initialization code that runs when the game loads to start the movement of the ball: float x = Random.value < 0.5f ? -0.75f : 0.75f įloat y = Random.value < 0.5f ? Random.Range(-0.75f, -0.5f) : Random.Range(0.5f, 0.75f)


Material: Bouncy (name of my physics material).Here are some of my current settings (if that helps): I have applied a Rigidbody2D component, BoxCollider2D, and a Physics Material 2D that is supposed to make the ball bouncy. Note that I have already tried to change the bounce threshold in Project Settings, but it does not do anything to solve my issue. My main issue is that a ball in my Unity 2D game doesn't bounce correctly when the speed is set to a lower value but works fine at faster velocities. I have already seen this question asked here, but this applies to Unity 3D, whereas I am working in Unity 2D.
