Firstly, it would be a great deal of help if someone could explain to me the differences between Dynamic, Kinematic and Static (especially if there is a box for static by the name of the object. I've looked at the APIs and tried playing around with them, they are so confusing. :/

Secondly, I understand that the physics engine evaluates first and can cause a collision (when the ball hits the paddle in my Pong game) but is there a way around this? I'm trying to send the ball in the opposite direction to which it hit the paddle by using OnCollisionEnter2D but this method gets called second and therefore the ball changes direction twice and the physics engine causes an unnecessary collision...

I have looked to tutorials on the movement in pong and tried following the tutorials but get the same problem (even though their game is faultless), this leads me to think that it's the Body Type property that is causing the physics engine to produce the extra collision because theirs is an older unity version. It could possibly be the bouncy material with no friction also, I don't know much purely because I'm a newbie to unity. I wonder whether anyone has had the same problem as me and can set me free.

Thanks in advance. I seriously appreciate any help I can get! :)

  • \$\begingroup\$ is there a way around this? Not likely. As for your first question: static means it never changes (no movement), kinematic means the object is moved via code, not the physics engine, the last means it's wholly under control of the physics engine. \$\endgroup\$ Mar 1, 2018 at 23:19

1 Answer 1

  • Static bodies have no Rigidbody component attached to them, so the physics engine does not consider them to be moving. (Avoid moving these frequently or you'll violate that expectation)

    Use static colliders for level geometry like the ground and immovable walls, or stationary trigger volumes.

    Static colliders on their own won't set off trigger/collision messages like OnCollisionEnter, unless there's a Rigidbody on the other participant.

  • Dynamic bodies have a Rigidbody component attached to them and their isKinematic flag set to false. These objects move at the whims of physics according to their velocities/angular velocities and the forces/torques and collision impacts exerted on them. The physics engine takes responsibility for resolving their collisions with static, kinematic, and other dynamic objects and rebounding them as needed.

    Use these for basic physics objects you want to be able to stack & topple and have them behave plausibly with minimal intervention, or for objects that you want to steer in a physics-focused way, like a rocketship.

  • Kinematic bodies have a Rigidbody component with the isKinematic flag set to true. This tells the physics engine "this object moves, but I'll handle that part" — the kinematic object will process collisions with other rigidbodies, but only dynamic objects will automatically react by bouncing away, and cause OnCollisionEnter messages to be sent.

    The kinematic object itself won't move except how you tell it to with MovePosition()/MoveRotation() — its velocity won't automatically integrate each timestep.

    Use this for objects that you want to control in ways that don't behave like simple physics bodies — like a bipedal character controller or highly custom vehicle controls. Use physics queries like overlap checks and shape casts to scan for collisions preemptively, since they won't stop your object automatically.

You can refer to the Collision Action Matrix at the bottom of this documentation page for a quick reference of what types of collision are checked for each type of body.

For your case though, I think a simple dynamic Rigidbody is all you need. Just set its collider's isTrigger flag to true. Trigger colliders detect collisions, but do not generate collision resolution responses. That way the velocity of the object stays under your control.

Instead of OnCollisionEnter2D(Collision2D collision), you'll listen for collisions with OnTriggerEnter2D(Collider2D other)

  • 1
    \$\begingroup\$ Dude, thanks to you and everyone else, I have nearly finished the game :) Thanks very much for your help! It's looking juicy now xD It all makes much more sense I think. \$\endgroup\$
    – user113025
    Mar 3, 2018 at 17:49
  • \$\begingroup\$ Most Clear explanation seen so far. \$\endgroup\$
    – AlexWei
    Nov 3, 2020 at 8:58

You must log in to answer this question.