Object did not collide with border - c#

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.

Related

Unity C# capsule collider and rigid body don't trigger using transform.position to move

I have 2 simple capsules. 1 is stationary and the other is moving to the same tile on the tilemap using transform.position.
Both capsules have capsule colliders and rigid bodies. I've attempted to remove the rigid body but from what I can tell, the OnCollisionEnter function requires a rigid body to work.
My script, attached to both of these, is a simple:
private void OnCollisionEnter(Collision other)
{
print("Collision Detected! " + other.gameObject.name);
}
I've used combinations of 'isKinematic', 'isTrigger', placing one component before the other then reversing, ensuring I have the script attached to both objects, making sure my capsule collider is sized to the object, and looked at other people's issues to try their steps to fix my issue.
Nothing seems to trigger the collision between the 2 capsules. It's got to be something small I'm missing.
I have a tag on both objects and have tried things like if(other.gameObject.tag == "myTag") {...} but that's not working for me, either.
Can anyone spot my mistake? Let me know if you need to see anything else - happy to provide images or whatever will help. Thanks in advance!
Above is the basic identical hierarchy of both capsules with components attached to the capsule mesh. Both have the parent empty objects they're stationed under. (Which themselves, contain scripts but no collider or rigid body)
Here is an infographic to show when a collision message will be detected by OnCollisionEnter between two objects. Both objects will need some sort of collider, and will most likely need a Rigidbody.
You will not want to set isTrigger as that will not make it physically react to a collision, but will just detect when a collision occurs. It will also not call OnCollisionEnter but will call OnTriggerEnter. Setting both not as triggers, adding a collider, and giving them Rigidbodies should allow the collision to be detected. You will also need to attach this script to one of the objects that have the collider. Are there other components on the objects you are using?
Make sure you are not looking for
void OnTriggerEnter(Collision collision){}

Unity C# - Collision sphere with cylinder - Not trigger sides of cylinder

I have a sphere collider on a stick and a cylinder. The cylinder has to detect a collision with the sphere collider of the stick and fire up a "OnTriggerEnter" script. Just imagine it like a drum stick hitting a drum in virtual reality.
Is there a way to avoid registering a collision on the sides of the cylinder, but only trigger on the top of the cylinder? And even without adding more protecting objects around it?
In the screenshot you see the properties of the stick and below the properties of the cylinder.
Obviously the green and red icons show which area is allowed to be triggered and which not.
Btw, simply using a thinner cylinder collider doesn't work in this case, because it wouldn't detect some collisions at all, when the stick goes too fast trough the thin cylinder. More about that in the comments.
Thank you.

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 Collisions - isKinematic Allows Objects to Go Through

I have a user navigating and colliding with a rigid body. I would like one object to slide along the other when the collision happens. It behaves this way when the isKinematic setting is NOT checked. However, the object then moves. I would like the object to stay in place when collided with. When I turn isKinematic off, the user is able to navigate through the rigid body which shouldn't happen. Any ideas on how to fix this?
As of now, I don't have any scripts associated with the rigid body.
If one object is moving and the other should be static:
RigidBody + Collider for the moving object
RigidBody (isKinematic) + Collider for the static object
So basically you are missing the Colliders to avoid GameObjects go through each other

Invisible Markers in game map - Unity 2D Game

How can I place specific points on my 2D tile map that are invisible and do not obstruct any movement in the game, and when the player interacts with this it fires some code. Any help would be great, thanks!
Let me know if more description needed
You probably want to use a BoxCollider2D as a trigger (i.e. set the IsTrigger flag to true). You can override the OnTriggerEnter2d method to fire off your code when something enters the bounds of the collider.
Setting the IsTrigger flag will cause the collider to NOT block any actors. It will simply trigger the events as the collider is entered / touched / exited etc.
See the API here

Categories