Prototype 1 Challenge in Unity - adding Rigidbody to game assets - unity3d

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 :)

Related

OnTriggerEnter not working for PolygonCollider2D and BoxCollider2D

I am running into an issue where OnTriggerEnter does not seem to be getting called. The Polygon collider should call it whenever another collider enters it, but for some reason it does not ever get called. Hoping someone could take a look at this and tell me what I am doing wrong.
PS. The
Picture of Code attached to Object 1
Object 1imgur.com/xRJrs.jpg
Object 2
Scene view with two colliders overlapping
Make sure all objects have are on layers that collide with each other. Edit > Project Settings> Physics2D > CollisionMatrix at the bottom
Make sure all Colliders are either Collider2D or just Collider, 2D does not collide with 3D.
Make sure the colliders are on Trigger (bool in Inspector) because you are using OnTriggerEnter
EDIT: Make sure you use OnTriggerEnter2D 2dPhysics dont interact with 3D physics. See 5.
3D physics dont interact with 2d physics
Good luck

In Unity 2D, how do I achieve Non-trigger collsion that doesn't "physically" move the rigidbodies?

I have a bullet game object and an enemy game object.
I want to have the ability of getting the collision point/contact, which's why I think I need the collider of the bullet to not be a trigger collider - this way, I want to have the bullet bounce off the enemy. At times, the bullet will need to bounce off of rectangular objects (not a problem), but I also want the bullet to bounce off of elliptic objects (the problem).
I want the bullet not to "physically" push the enemy, which is why, intuitively, I should set the bullet's collider to be a trigger collider.
When the bullet's collider is a trigger collider, I seemingly don't have a way to implement the bouncing.
But when the collider's not a trigger collider, it pushes the enemy object.
There's no code errors, but I think the code hasn't got anything to do with the problem.
I suspect the problem may have something to do with the Physics Collision Matrix.
EDIT
It seems that raycasting would be the solution to the problem, as Leoverload proposed. My problem became a different problem now, so I'll close off this thread, and open a new one.
Thanks for the help, #Leoverload ! :D
For the position of the hit it's very easy. You must have 2 colliders and 2 Rigidbody and then you can simply add a
Void OnTriggerEnter2D(Collision Coll) and inside it check for the tag : if(coll.compareTag("surface")) and inside you can get the position with collision.transform.position.
The collision matrix on the Physics menu only allows to remove Collision between certain layers, it's useful if you want the enemies not to push eachother!
If you don't want the player pushed you can change the collider to trigger, and destroy the bullet just after the collision with the same method as before with a void OnTriggerEnter2D and the compareTag. In this way it will look like it touches the enemy and explode, but it won't actually touch anything. If you want to add knockback to the player then you could do a simple AddForce based on the direction of the bullet and the work is done!
If you want to avoid the bullet to move walls you can set walls to static and it should work fine

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.

How can i add a collider for the elevator to prevent from the character to walk through the object?

The character can enter the elevator but the problem is that he can also walk through the walls from sides and behind.
And if i add a box collider or any other collider/s they will prevent from the character to enter the elevator. It's not my elevator object it was made in blender.
Use Compound Collider instead of Mesh Collider.
Create new empty GameObjects called back, front, right, left, top and bottom
then attach Box Collider to each one. Manually resize and move each one to match the size of the elevator on all sides.
Once that is done, put them in a parent empty GameObject then put that parent GameObject under your elevator GameObject so that the colliders will move/rotate with the elevator. Finally, disable or move the front Collider GameObject via code when you want to allow the player to enter inside the elevator.
The image below shows example of what individual collider should look like and the final look:
These sorts of questions are better off in the Unity Answers, as this isn't a programming question. Please keep that in mind for future questions.
To answer your question though,
Find the mesh in your Project Files in Unity, there is a checkbox for 'Generate Colliders' - check this box and press apply.
Finally, on the GameObject with the mesh, add a MeshCollider component.
If the model is set up correctly, your mesh collider should now use the model for collision.
If this does not work, as an alternative, you can use cubes with colliders and 'build' the collision mesh yourself, and parent the objects to the same object so they move with the lift, before disabling the MeshRenderer component so they will not render.

Unity2D - Level with invisible collisions

In my Unity2D project I want that to load a level as a sprite from my resources. The game is a top down view. I then want to add invisible collision boxes where the walls in the level-image are.
How would I do that?
I have attached a box collider to my player and now? Creating an empty game object with another box collider doesnt work.
See #Savlon comment, you need rigidbody with your collider component as well for empty objects. And they will provide blocking of player object if you player object also have collider and rigidbody. Don't mark your colliders as trigger and ensure they are on the same layers.