Multiple Colliders - How to make a collider invisible to certain objects - c#

Basically I have teleport zones set up to access new areas within the level. This is only supposed to respond to the player's box collider. However, I attached a cube to the player, disabled the mesh render and use its collider to detect enemies. Unfortunately, the detect enemy collider touches the teleport zone and warps me to the new position well before my player gets near it. I tried to change the tag on the enemy detection collider but it still teleports.
How do I go about making the teleport object ignore the player's enemy detection collider?
I'm using Unity 5.3.8 and C#

Change player's GameObject layer to Player. Then, create a new layer called Teleports. Go to Edit -> Project Settings -> Physics. Then, under Layer Collision Matrix, in Teleports row uncheck everything except for column under Player.
Now, objects in Teleports layer will only collide with objects in Player player.

Related

How to detect collisions for a rotating child object in Unity3D C#?

I am making a First Person Shooter and I have a rigged player with a mouse look script, and I used to rotate the spine with spine.transform.rotation, but this method does not look for collisions, this means if I rotate and I am standing near to a GameObject, I glitch/bug through the object. So I tried to do it with a Rigidbody but this doesn't seem to work, I tried: rbSpine.AddTorque(new Vector3(mouseLook.y,0,0), ForceMode.Force);. This doesn't do anything. And I have another problem with the Rigidbody, I've only a rigidbody attached to the spine, my player has multiple simple collision and these overlap eachother a little, and my rigidbody is pushed away into the air slowly. Does anyone know a solution for this?
I put a rigidbody component on the player, this will take care of the collision detection for itself and all its child objects.

How to detect mesh collision in Unity3d?

Can we detect mesh collision in unity3d? I want to show some texture on collision, currently I am using box colliders, that's why its surface/edge do not match with the object body mesh, Also even if I get the hit point on the surface of mesh, I don't know how to put a texture on a mesh at specific position over mesh, is there any in-built component specific for the same kind of requirement or a workaround of this in unity3d?
As we can see in picture the collision has been detected inside the game object because the box collider is inside the target object mesh
Note: here the actual mesh I have replaced with a dummy cube mesh
But is there any way to detect when bullet collider/mesh was actually going through the mesh of the target object as in below image I have shown where exactly I want to detect the hit point between target object mesh and bullet mesh/collider also how to draw a texture over here (the hit point on the mesh).
Short answer: No
Because that's not how that works.
Long answer:
If you want the mesh to be used as the collider, you should set the mesh as the target for a MeshCollider component. However, mesh colliders are very expensive: Unity needs to recalculate them every time they move, scale, rotate, or otherwise change their boundaries.
There is, however this asset which will perform raycasts against the renderer mesh, without the need for a collider, but I have no idea what kind of performance hit that will have.

unity: fix Player passing through objects

After updating from unity 5.5.2 to 2017.3 the Player character does not collide with objects(evironment asset) and is passing through them, all the objects have mesh collider with convex on, This is only happening in one of the level(scene) in the game while in rest of the level(scene) the player behaves normal and is colliding with objects.
Player settings
object settings
The player's rigidbody is kinematic. I would try by disabling that property.

Unity 2D collisions not being detected

I have been following the Unity 2D rougelike tutorials. The inspector returns no console errors when run.
The player moves on a grid and should collide with objects, some should trigger upon moving over them and others should prevent movement, the objects that activate upon trigger work as intended. The player has a Rigidbody 2D and Box Collider 2D and is set to is kinematic. The objects that do not work as intended are the walls, the outer walls should block movement entirely, the inner walls should be breakable and the enemies can not be damaged or damage the player. The walls all have a Box Collider 2D. The enemies also have a Rigidbody 2D and is set to is kinematic Game
It's normal that the walls don't block your player. You have set the isKinematic to true. What that does is
Controls whether physics affects the rigidbody.
So when you set it to true, physics no longer affect your player and he will not collide with anything.
From the Unity documentation:
If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position.
You should set the isKinematic to false if you want your player to be able to colllide with different objects.

Object did not collide with border

I'm stuck on this sphere has a CircleCollider2D and rectangle has a BoxCollider2D i increase the offset of BoxCollider. But why sphere not collide from it's border. Sphere go inside and then collide just like this.
I want that it's collide when sphere touch it's border.I also check with default radius but the same situation occur.
Trigger
The scripting system can detect when collisions occur and initiate actions using the OnCollisionEnter function. However, you can also use the physics engine simply to detect when one collider enters the space of another without creating a collision. A collider configured as a Trigger (using the Is Trigger property) does not behave as a solid object and will simply allow other colliders to pass through. When a collider enters its space, a trigger will call the OnTriggerEnter function on the trigger object’s scripts.
http://docs.unity3d.com/Manual/CollidersOverview.html
You need to close isTrigger and use OnCollisionEnter(...).
For example this is my script of wood(which is below ). A smaller wood will be going down.
This is the beginning of my game
If I set isTrigger option true, onCollisionEnter2D function doesn't work. I need isTriggerEnter() method instead. it goes through my wood layer.
But if I set isTrigger false onCollisionEnter2D will be working. It will stay on my wood layer.

Categories