x


Is there a way to know, in a group of colliders, wich single collider is being hitted?

Hello everyone, I have a type of weel made by one or more cells that can rotate simultaneously around an object. Each cell has a collider on it and i have created a script placed on the parent object of these cells with OnMouseDrag() event that rotateS the structure. Now, how unity references say, cell's colliders are now handled like a single collider and there is no problem with this. But what i would like to know is wich cell is being hitted or how i can change my structure in order to obtain this result? Tanks in advance!

more ▼

asked Jan 12 '10 at 01:48 PM

Frenses gravatar image

Frenses
27 5 5 11

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I have a similar situation where I want to know exactly where on a collider i am hitting and I use the coordinates on the texture that was hit to help determine exactly where on the object it was hit.

Ray MyRay = MyCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit MyHit = new RaycastHit();

if (Physics.Raycast(MyRay, out MyHit, 120f))
{
string name = MyHit.collider.gameObject.name;
Vector2 pixelUV = hit.textureCoord;
if( name=="WhatImLookingFor")
{
pixelUV.x *= WidthOfTexture;
pixelUV.y *= HeightOfTexture;
...
}
}

Does that help?

more ▼

answered Jan 26 '10 at 05:01 AM

thom gravatar image

thom
119 2 4 9

(comments are locked)
10|3000 characters needed characters left

you can give a spesific name to each of them and then you can recognize them with their name. if you want to see wich is clicked you should trace a ray from mouse position to see what will be collided. also you can use the GetInstanceID() to get the unique id of the collider and compare it to a pre built list of collider ids.

more ▼

answered Jan 12 '10 at 02:03 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

Thanks for the answer Ashkan. I already have assigned unique name to each cell but, i can't hit them singularly becouse my cells are grouped in a gameobject acting like a container that will receive implicitly collision instead of my cells. Maybe i'm asking a stupid question but maybe someone have solved it.

Jan 12 '10 at 03:10 PM Frenses

put your code here then i can help you. where do you check for the collider? how do you check it?

Jan 12 '10 at 05:40 PM Ashkan_gc
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1687

asked: Jan 12 '10 at 01:48 PM

Seen: 1143 times

Last Updated: Jan 12 '10 at 01:48 PM