OnTriggerEnter being called on unexpected object - c#

Maybe I have a misunderstanding as to how OnTriggerEnter is supposed to work but here is my situation and how it differs from what I would expect.
I've created a very simple test project with a single scene. I have three objects in my scene - a player, an enemy, and an attack. The enemy and player both have rigid bodies and box colliders, neither of which is a trigger. The attack object has a box collider that IS a trigger. For scripts, the player has a script with nothing in it other than an OnTriggerEnter function that logs info to the console. The enemy has a simple script that just enables and disables the attack object in a cyclic pattern. When the attack is enabled it collides with the player.
Github with cloneable project/code: https://github.com/valevalorin/TriggerTest
What I would expect to happen:
The attack object is enabled and collides with the player. No console output is logged. The player object does not have a trigger collider on it so it's OnTriggerEnter should never be called.
What actually happens:
When the attack object collides with the player, the player's OnTriggerEnter function gets called and output is logged to the console.
As far as I can tell, OnTriggerEnter should only be called on objects that actually have a trigger associated to them. Is this not how OnTriggerEnter works?

From the documentation:
Description
OnTriggerEnter is called when the Collider other enters the trigger.
This message is sent to the trigger collider and the rigidbody (or the collider if there is no rigidbody) that touches the trigger.
Emphasis mine.

Related

Unity 3D OnCollisionEnter

I'm trying to make my player jump only when they are touching the ground and to do so I made an OnCollisionEnter(Collision collision) function, then I made another function called jump which makes the player jump when the space button is pressed the on the CollisionEnter function I call this function however this does not call the jump function, what am I doing wrong? when the player collides with the ground though it does print It's jumping as I have made a Debug.log check.
OnCollisionEnter function is called only once, when your player collide the ground.
If you want to do that you have to use a "isGrounded" boolean variable which you set to true when is grounded (in OnCollisionEnter) and set to false when you press jump.
The jump control must be in the Update function.

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

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.

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.

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.

Very strange trigger behavior in Unity2D (4.5)

I am developing 2d platformer and I've faced with a very strange triggers behaviour in Unity. I have made the enemy that can throw objects into main player. So I have made two empty GameObjects with Circle2D colliders on them and attached them into the enemy GameObject. The first trigger ensures that when enemy hand will pass through it, it will spawn an object that will be thrown in future, and the second trigger is responsible for the throw that object into player. The first trigger ensures that when the enemy's hand will pass through it, it will spawn an object that will be thrown in future, and the second trigger is responsible for throwing an object into main player. Every trigger has a Rigidbody2D component attached to it. The hands of the enemy have tags "right hand" and "left hand" and I am checking the in the OnTriggerEnter2D method. This method is calling and I have log messages and this method is detecting that left or right hand are entering trigger. But the problem is in that this method is calling when the hand has already passed through trigger and get out of its bounds. Can anyone help me and explain why this is happening? I have attached a picture where I draw a scheme and described my problem.

Categories