Ball.velocity at Start

Hi!

When I’am start the game - I do nothing, but Ball.velocity (Y) falling down!
And after about 5 sec happend collision with Lose wall and Game Over.
Wherein picture of Ball stay at platform all the time.

But if I click on Mouse after start the game (Ball goes UP) - It will be OK!

What’s happed?))

Hi Сергей,

Check the Collision Detection for the Rigidbody2D component and set it to ContinuousDynamic for the ball.

Hope this helps :slight_smile:

1 Like

Gravity is making the ball fall down. You have two options to turn gravity off:

  1. TURN GRAVITY OFF FOR THE BALL
    Go into the inspecter for the Ball prefab, scroll down to the Rigidbody2D component and uncheck the box that says “use gravity”.

  2. REDUCE ALL GRAVITY TO 0
    Go into Edit menu at the top of the Unity editor and scroll down to Project Settings. In the Project Settings window, go down to Physics (or Physics2D? I don’t remember.) Near the top should be an option for gravity. it’s -9.81 in the y by default, but you can change that to 0.

1 Like

Hi Rob,

Thanks a lot!

In which situation Collision Detection for the Rigidbody2D = Discrete ?
I can’t imagine…

1 Like

You’re very welcome

Basically, there is a higher overhead with continuous and continuous dynamic, so if you are not experiencing any problems, use discrete.

You may find that just changing the collision mode on the ball is sufficient. When you think about your game, it is the ball that is causing the majority of collisions and is likely to be the only fast moving GameObject (unless you enhance with some other features). Then, based on your level design, possibly your blocks, paddle and walls. Tweak one setting on one thing at a time and play-test. :slight_smile:

Hope this helps :slight_smile:


See also;

1 Like

Rob,

Why in Video teacher doesn’t explain this problem?
i have cheked settings of the ball in Video - it is Discrete
Or teacher has same problem but doesn’t show it?..

Also I try it, but it is useless:

void Start ()
{
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
}

Why velocity falls down if ball has same place in space?
And what is falling down in this case?

From docs.unity:
“When you set the Collision Detection to Discrete , GameObjects with Rigidbody 2Ds and Collider 2Ds can overlap or pass through each other during a physics update, if they are moving fast enough.
But I didn’t make any speed for ball at start…

Ohhhh…
Sorry for my stupid questions but I want to understsnd it…

Hi,

Do you have gravity enabled? If you check the Rigidbody2D component on the ball, is the Gravity Scale set to 1? If so, you have gravity enabled. If the project settings have a value for gravity, above 0, then there will be some form of downwards movement for objects affected by physics.

Anthony mentioned this is his reply above.

Check the Rigbody2D component and see if this is set. :slight_smile:

1 Like

Hi Rob,

Yes I have gravity enabled!
I also understand that objects affected by physics.

But I don’t understand why Ball picture stay on platform but Ball Collider falling down?
Why it’s separate?

Hi Sergey,

Could you perhaps zip your project files and share them so that I can have a look at the issue please?

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.

I have uploaded to Google Drive - “Blok_Breaker.zip”
Reference

Thanks, but it’s asking for permission, can you set it to be publicly available please.

Rob, sorry!
Check now please…

Still stating the same thing, there may be permissions on both the folder you have the zip file in, as well as the zip file itself.

Check it please:
Link

1 Like

Perfect, downloading it now :slight_smile:

1 Like

This is definitely related to a combination of the items mentioned above.

I believe what is happening is that the physic engine is calculating where things should be, gravity is taking affect so the calculation is including the downwards movement of the ball. At some point, there is a calculation which detects a collisions between where the ball will be and this triggers your OnCollisionEnter2D method.

Whilst the ball is not fast moving at this stage, calculations must have taken place which see the ball making contact with the lose collider, effectively falling through your paddle, in between collision detection for the ball and the paddle due to their discrete setting.

As stated above, the two ways to combat this are to either remove the force which is being applied to the ball, in this case, gravity. Or, to change the collision detection mode so that the checks are taking place more frequently. If you change the collision detection for the ball to Continuous this no longer occurs.

1 Like

Rob,

Thanks a lot again!

You’re very welcome :slight_smile:

Just to add to the above, I found this online which I think probably describes what happens better than I did above;

“There is a chance that your small object is on the one side of the terrain in one frame, but already on the other side in the next frame and collision is not detected. If you have a rigidbody on your small objects, try to change the collisionDetectionMode to ContinuousDynamic.”

In the above, the issue was with terrain but effectively anything with a collider on it would produce the same result, like your paddle for example. They are also referring to 3D rather than 2D, so your solution would be to use Continuous on the ball as the collision detection mode.

So, the ball is above the paddle in one frame, the other side of the paddle in another frame, with the collision between the ball and the paddle not being detected. After this the ball is able to fall freely to the lose collider and trigger the collision which ends the game.

This would align with the documentation, frame one, on top of the paddle, frame two, ball is under the paddle, that’s the new position - discrete collision detection says “no collision at new location”, ball falls to lose collider.

Hope this helps :slight_smile:


See also;

1 Like

Privacy & Terms