How do I make GameObjects use physics to interact with each other using Vuforia? - unity3d

I'm using Vuforia for an AR school project and am trying to make a Roll a Ball game. However, the ball keeps falling through the ground despite the fact that both the ground and the ball have colliders. How can I the ball interact with the ground?

In general you always need at least one Rigidbody in order to get collisions via the physics engine.
A Rigidbody
is the main component that enables physical behaviour for a GameObject
What you would probably use for that is a kinematic Rigidbody on your moved object.
This is a GameObject with a Collider and a kinematic Rigidbody attached (ie, the IsKinematic property of the Rigidbody is enabled). You can move a kinematic rigidbody object from a script by modifying its Transform Component
but it will not respond to collisions and forces like a non-kinematic rigidbody. Kinematic rigidbodies should be used for colliders that can be moved or disabled/enabled occasionally but that should otherwise behave like static colliders. An example of this is a sliding door that should normally act as an immovable physical obstacle but can be opened when necessary. Unlike a static collider, a moving kinematic rigidbody will apply friction to other objects and will “wake up” other rigidbodies when they make contact.
Even when immobile, kinematic rigidbody colliders have different behavior to static colliders. For example, if the collider is set to as a trigger then you also need to add a rigidbody to it in order to receive trigger events in your script. If you don’t want the trigger to fall under gravity or otherwise be affected by physics then you can set the IsKinematic property on its rigidbody.
For detailed information also refer to Unity Manual - Colliders and in particular the sections Collider Interactions and Collision action matrix

Related

Reduce collision hit between objects

I am using rigidbody on my object but the when the collision occurs between two objects, it flies off. I want the collision to be minimum. What should I change in my rigidbody settings?
In the collider component add a physics material and in the physics material scriptable object change the bounciness and the same for your other object with which it is colliding.

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

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.

Collision Events in Unity3D

I noticed that OnCollisionEnter2D does not trigger when two objects with Collider2D components make contact. It only triggers when one of them has a RigidBody attached to it. This seems odd to me, because the Unity editor itself says that having a static collider in place of a non moving RigidBody is much better for performance. Then why does Unity not allow two game objects with static colliders trigger collision events when they make contact?
Sure, static colliders are more performant, but as the word indicates: they are static.
Movement requires physics calculation and therefore a rigidbody (which holds information about speed etc.). This is actually stated in the docs for the normal collision here http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

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.

Collision detection, without the physics?

I have enemies following a path in my game. Along the path I have turrets shooting at them. To get collision detection between the bullet of the turret and enemy i've added RigidBody2D, and Circle Collider 2D to the enemy, and Circle Collider 2D to the bullet.
When the bullet hits the enemy it shall not push the object, just destroy the bullet and take some of the health.
I feel Rigidbody2D is messing it up, it gives mass, drag and gravity to my enemy... but I dont need it. But it seems I do if I want to have collision detection bewteen two objects?
You need Rigidbody to detect collisions, however you are just triggering some actions (taking damage). That is why you can check isTrigger on your colliders, and then implement 'OnTriggerEnter2D' callback instead of 'OnCollisionEnter2D', which won't activate any physics.
See http://docs.unity3d.com/Documentation/ScriptReference/Collider2D.OnTriggerEnter2D.html for reference.