Objects pass through the player object - unity3d

I have spheres and a player gameObjects, the balls enter the player even though it has a rigid body and a collider, this is how the player is defined:
It has several child objects but none of them has a rigid body or a collider.
This is how the spheres are defined with its sphere child:
The spheres are moved only like this transform.GetComponent<Rigidbody> ().AddForce (dir.normalized * ForceFactor);
So what is causing them to go into the player?

Your player and enemy object both has collider's property IsTrigger enabled. Check out documentation on trigger - it's mentioned that trigger doesn't register a collision. You should use not trigger mode colliders (for both object) to register collision properly and don't allow object to pass through each other

Related

Character falling through floor unity

I had this working just fine until I decided I wanted to change how I organized the colliders just a few minutes ago to avoid having multiple colliders on the same object.
I have a "Player" object with a boxCollider2d with isTrigger=false and an empty child called "triggers" which itself has 2 children, each with a single boxCollider2d and both with isTrigger=true. These triggers are used for detecting when the player is grounded or next to a wall but are not supposed to affect the physics.
I also have a "floor" object which has a sprite and an empty child called "colliders" which has a single child called "ground" with a single boxCollider2d (isTrigger=false) and the layer of the object set to "Ground".
My understanding is that since my player has a non-trigger collider (and rigidbody) and the floor has a non-trigger collider (at least its child does), that the character shouldn't pass through the floor. Also, it's starting from a height above the ground so it's not an intersection problem.
My best guess is that somehow the child colliders of the player being triggers are turning the main collider into a trigger or that for some reason the floor collider being in a child is screwing with it, but I don't know enough about how these colliders work to really know.
The child trigger colliders should not cause it to mess up like that.
Check Project Settings -> Physics 2D -> Layer Collision Matrix. Are your objects not able to collide?

Does a VR object need a Rigidbody for a collider?

In Unity3D, you need rigidbodies on GameObjects that use colliders, as they use physics. You don't need rigidbodies on static GameObjects because they don't use physics, though you still need to have at least one in the calculation.
My situation is this: I want the game to detect putting your head through a wall with colliders. I'm just curious, as the collider on the head won't use physics, does it still need a rigidbody as it's moving, just not with physics?
My question is: Does a VR object need a rigidbody? (and yes it set it to kinematic)
Colliders → Collision action matrix
=> It depends.
Some of the combinations only cause one of the two objects to be affected by the collision, but the general rule is that physics will not be applied to an object that doesn’t have a Rigidbody component attached.
You said
as the collider on the head won't use physics
But note that in general Collision = Physics.
So yes, at least one of the objects involved in a collision needs to be a (kinematic) Rigidbody.
As you can see in the matrix above e.g. for a collision with a static object the event (like OnCollisionEnter) will be invoked only on the object with a (kinematic o not) Rigidbody but not on the static object.
static here means it has no Rigidbody component attached even if it is moved by code or in other words: As soon as something moves in your scene it should have a (kinematic) Rigidbody component!
You can add colliders to a GameObject without a Rigidbody component to create floors, walls and other motionless elements of a Scene. These are referred to as static colliders. At the opposite, colliders on a GameObject that has a Rigidbody are known as dynamic colliders.

Unity - handle OnCollision on child's Rigidbody

I have a GameObject, constructed from bunch of pills, where each pill is basically constructed from two spheres and a cylinder.
So the GameObject hierarchy looks something like this:
Player (Empty GameObject)
Pill (Empty Game Object)
Sphere (3D sphere)
Cylinder (3D cylinder)
Sphere (3D sphere)
Hopefully the picture will give you guys the visual illustration of what the GameObject looks like:
Now, my goal is to have the entire GameObject - Player as a Rigidbody, while I would like to detect collision on Pill level. Hence I added Rigidbody to Player and Capsule collider to each Pill. However such configuration does not work - the Pill does not receive OnCollisionEnter event. I found suggestion solution, however it does not work for me either - if I set Capsule collider property Is Trigger, then Player does not interact with other Rigid bodies. The only solution I found so far is to add Rigidbody to each Pill, but I am concerned about performance is such scenario.
To sum up - my question is - can I have the above configuration - parent rigid body, child collider work and accept OnCollision events? Of course if I can have parent rigid body and a child with Is Trigger set will also work in case the Player keeps rigid body physics behavior.
I don't know why you want to detect collision on Pill Level but retaining the same configuration one thing you can access is the Collision ContactPoint.

How can i Prevent Kinematic object not to pass through another rigidbody object

I am developing an oculus Home like project where i am facing a problem of object passes through walls and other objects. The scene is described as, Ialt texthave an object that has Box Collider and an Rigidbody (Gravity false , Kinematic true) A wall and a Floor with Box Collider and Rigidbody(Gravity false , Kinematic False) I am moving an object with hands movement. Translate object near and far using thumbstick, the problem is that when i move object far the object pass through the wall and floor. As you can see in the image below the object is passing through in the walls and the floor. Please help me and suggest a better solution. Thanks in advance.
the idea behing Kinematic objects is that interaction with Physics will not alter their transforms, so they will pass through other static or kinematic objects. To alter that you can either not use Kinematic rb's or detect collisions manually and adjust for collision results
I think you have one of your collider's Is Trigger set to true.
If the collider on your object has the Is Trigger property set to true then the collider will pass through other colliders but if it's not a trigger then it'll always collide with other non-trigger colliders. So as long as you have two non-trigger colliders they'll always collide no matter the rigid-body and if you need the Is Trigger property set to true there's a workaround you can use two types of colliders on a single object one a trigger and another a non-trigger preferably a Mesh Collider (so the trigger collider will have space to be triggered).

collision not happening for same object in unity

objects are not fast moving, they are very slow 6 same objects sometimes collision works sometimes not for same objects? Is it usual?
I am using ontriggerenter everything is working but sometimes some object on hexagon not collapsing.
1 ball hitting 6 same pieces. 5 of them collapsing 1 is not collapsing every time, and its changing
their tag is same name
OnTriggerEnter would not allow a physics interaction from two objects. The GameObject with the Collider set to isTrigger = true would pass through the other object. From MonoBehaviour.OnTriggerEnter(Collider):
Description
OnTriggerEnter is called when the GameObject collides with another GameObject.
The given other Collider has details about the trigger event, such as the name of its GameObject. Either of the two GameObjects must have a Rigidbody component. The Rigidbody component has both Rigidbody.useGravity and Rigidbody.isKinematic set to false. These prevents the GameObject from falling under gravity and having kinematic behavior. One Collider has Collider.isTrigger set to true. The GameObject with Collider.isTrigger set to true has OnTriggerEnter called when the other GameObject touches or passes through it. OnTriggerEnter occurs after FixedUpdate ends.