Should we never have a collider component on a game object unless we also have rigidbody? - unity3d

After watching this (from 13:12 to the end) official Unity tutorial I have a question: Does this mean that ideally we should never have a collider component on a game object unless we also have rigidbody? Because if we only have a collider, Unity will consider the game object as static. So we should always add rigidbody and indicate that it is Kinematic.

It is perfectly fine to use colliders on static objects that don't move without adding the rigidbody. It is even better for performance as these colliders are cached in the physics engine.
There is no point in adding a Rigidbody to lets say a floor, that will never move.

Related

Understanding what causes collision events

https://docs.unity3d.com/2021.1/Documentation/Manual/CollidersOverview.html
While getting some basic collision detection set up I referenced the official docs on the matter. Unfortunately, this left me more confused than when I started.
I made a simple scene. In this scene I added a sphere with a sphere collider (non-trigger) and a Kinematic Rigidbody. A script moves this object on the X axis when played.
I then created cube with a box collider (non-trigger). This object has no rigidbody or scripts attached.
Looking at the chart in the documentation linked to above, this should fall under the Static Collider and Kinematic Rigidbody Collider interaction, which should not create collision events.
However, if I add a OnCollisionEnter() to the sphere, it will call this method when the objects collide. Without physics they both continue on their way, otherwise oblivious to each other.
My concern then is that either the documentation isn't entirely correct or I have a fundamental misunderstanding of what it is telling me.
What's going on here?

Prototype 1 Challenge in Unity - adding Rigidbody to game assets

I have added a Rigidbody to each of the obsticles in the Prototype 1 Challenge in Unity. The "player" (plane) game object already has a rigidBody attached. However, when I play the game the plane passes through the obsticles.
How can I make the obsticles solid. I want to use them as triggers to remove points from the player when they collide?
Suggestions:
If you use any collider as a trigger then other objects will pass through it no matter if they are colliders or triggers so just uncheck that property (in your case its box collider) uncheck all of 'is Trigger' then they will become the collider as you want them to be and after that you can have some script which detects collision to check if you collided with obstacle you remove the points from player.
Hope it works... Happy coding :)

A collider is better to be static when checking collision?

So... As far as I know it's only good practice to make any GameObject Static if that object is not meant to move, therefore I also thought even a rolling stone with a rigidbody shouldn't be a static GameObject.
However, I was commented by someone as a 'Unity Tip FYI' the physics calculation spikes up when an object checks collision whilst it's rotating, so to make the collider static for the sake of better performance(even meer small amount).
I'm really not getting this idea.
Does this make any sense to anyone here??
Not exactly sure what that comment is saying. It doesn't make sense. Also, it looks like you are confusing static collider and marking GameObject as static.
Marking Object as static from the Editor
Telling Unity to batch it. It is used to increase rendering performance. (This has nothing to do with colliders)
Static Collider
Telling Unity that the Rigidbody will not be moved.
From your question, you are describing Static Collider. Static Collider work for both 3D and 2D physics system.
What is a Static Collider:
Static Collider is when you have a GameObject with any type of collider but no Rigidbody attached to it.
How to create a Static Collider:
To make a GameObject a Static Collider on, attach a collider to that GameObject but don't attach Rigidbody to it. It is now a Static Collider.
To make it non Static Collider, attach Rigidbody to it.
What it is used for:
When you have many Objects that you want your collide with but you are 100 percent sure that this Object will not be moved by you or player.
One good example is a brick wall. You simply want the wall to stop the player but you don't want to move the wall. It could also be used for stones in an environment to prevent player collison. Imagine having to attach hundreds or thousands of Rigidbodies to each stone Object with a collider.
It is used to increase physics performance.
What happens when you move a Static Collider:
Don't. When GameObject is made to be Static Collider, it is expected that you never move it. If you do, it will spike cause spike in CPU. This introduces constant freezing in your game each time you try to move it. This spike has been reduced in Unity 5 but it is still there. I think that's what that comment is trying to say. This whole thing happens because it has to recalculate the physical world all over again. From Unity's website, below is a screenshot of what happens when you try to move a Static Collider Object.
A static game object is not the same as a static rigidbody/collider, they're two completely different concept.
Static game objects are used to save performance time/memory regarding rendering, navigation meshes, etc., you can read about them here: https://docs.unity3d.com/Manual/StaticObjects.html
Static colliders are a totally different beast. A static collider is used to tell Unity that this object will never move under any circumstance, so it will save quite some calculations in the physics engine.
Finally, regarding the tip that you mentioned: I think that probably the author of that tip was talking about 3D colliders, and by "static" he meant that you should separate the 3D mesh from the 3D collider, so when the mesh must be rotated, you rotate only that and not the collider.
Think of a sphere, you create a parent game object, then two children: one that has the Mesh component, and the other the Sphere collider. When you want to rotate the sphere in place, you only rotate the mesh child and not the collider, and when you want to translate instead the sphere, you just translate the parent game object in order to change the position of both children.

RigidBodies without Extra Physics Behavior in Unity

Currently I'm making a racing game.
I move my cars with the Transform.translate class.
Now the thing I want for my cars is not to move through each other.
I attach colliders and a RigidBody to my player car and it's working.
But my problem is that each time my CPU cars and player car encounter with each other, my player car shows unrealistic behavior like moving out of the screen or throwing away.
I know this is part of the physics engine behavior but is there a way to make the RigidBody only do one job and make objects not to move through each other not to add other physics behavior?
Any ideas?
There are just few problems:
1.You don't move Rigidbody with transform.translate. When you do this, colliders will go through other colliders.
You move Rigidbody with Rigidbody.AddForce, Rigidbody.velocity and Rigidbody.MovePosition. By moving Rigidbody with these methods, collision should be functioning properly.
2.You are not even supposed to move the Rigidbody of the car.
Use WheelCollider. There are many online tutorials on how to set them up on the internet but Unity's documentation is fine too.
WheelCollider.motorTorque is used to move the car forward or backwards.
WheelCollider.steerAngle is used to steer the car.
WheelCollider.brakeTorque is used to brake the car.
If you need further help, you can find a fully working WheelCollider samples here.

Do I need a rigidbody for gameobject that scales up and down?

I have a beginner-like question. I currently have a gameobject in my scene that scales up and down via animation. It has a Circle Collider 2D on it.
I've seen some tutorials before regarding the performance optimizations of rigidbodies and colliders. I learned that if the gameobject should move in the game, it should have a rigidbody component. Otherwise, a collider component itself is fine for triggers.
Since my game object is kind of moving (because of the endless scale up/down animation), would it be best to put a rigidbody component on it?
I do like to mention that I'm not using any physics movement such as AddForce or anything like that. Hope someone can clear this up.
A gameobject should have a rigidbody component for mainly two reasons, first one is if you are using physics, second one is if you want other colliders to detect a hit/entrance/exit by that gameobject.
From what you described it does not seem like you would need a rigibody on your gameobject, especialy because the movement is only by scale and not by position.
and also, just to clarify, putting a rigidbody component on a gameobject is not a must even if the gameobject is moving. there are different ways to move objects, and rigidbody usually helps in case that the movement should be very realistic and interact with other gameobjects it is colliding with.