Unity detect click to 2d object without collider component - c#

I want to detect gameObject with no collider under mouse.
I tried RayCast. But its work only for object with collider component.

You have to add the collider. But you can set it to isTrigger and avoid collisions.

Related

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.

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.

capsule collider not jumping in unity

i imported a the Unity chan character from unity assets store , when i and i added to it rigidbody and capsuleCollider ,and then i assigned to it the
JUMP00 animation as in the images , so when i hit play the character jumps but the collider is not moving up , when i add motion to move x and z axis the collider moves with the character.
This behavior is by design. Animation only move the mesh, it does nothing to collider.
One workaround to this problem is that you can attach your collider to the bone not the mesh.
I just solved my problem which has the same behavior. The cause of my problem was because I did not move the GameObject (up), I just was playing the animation, not make a really jumping for the object.
I know this old post, but I answered for the newer game programmer like me :)

Unity/C# Trigger Making something else dissapear

Im trying to make it so that when i trigger a trigger in Unity, it doesnt remove the trigger, but it does remove what the trigger is attached to. but i cant seem to figure out how to do it.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("pickup"))
{
audio.Play(); //Play it
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
This is an example of what im trying to do, but imagine it trying to set something else to inactive.
When you deactivate the game object, the attached collider will be deactivated too. If you want to deactivate a game object and let the collider exist you need to distinct between those two, i.e. have two game objects: one just for the collider and one for the actual object. now you can remove the actual object while the collider can continue to function.
The implementation depends on how you are handling the trigger.
case 1:
OnTriggerEnter is written in a script attached to the game object which static collider (ground) is attached to.
static collider is a collider without a rigidbody.
add a child to this game object and put the visuals in it (i.e. renderer or audio source).
add public GameObject Child; to the script.
set the reference of the child via unity inspector window.
deactivate the child instead of collider's gameobject in OnTriggerEnter method: Child.SetActive(false);
case 2:
OnTriggerEnter is written in a script attached to another game object which also has a dynamic collider (ball) and a rigidbody.
dynamic collider is a collider with a rigidbody.
add a child to the game object which the static collider is attached to
add a script to the game object (MyScript)
add public GameObject Child; to the script.
set the reference of the child via unity inspector window.
deactivate the child instead of collider's gameobject in OnTriggerEnter method: (other as MyScript).Child.SetActive(false);
When you deactivate an object with gameObject.SetActive(false); you automatically deactivate every component on you object (Renderer, Triggers, Scripts, ...)
There is two options to achieve what you want to do:
Use another object as a trigger (a Plane or a Cube and deactivate your object from this new object)
Or as suggested by #madjlzz you can deactivate your Renderer and RigidBody

Categories