x


what is the best way to detect if an object has been clicked on?

i have one main script which uses raycasts to do various actions depending on what object is clicked on. currently the objects you click on either have box or mesh colliders but these are very unreliable at picking up the click, or you have to be very specific where abouts you click on a large object.

any help would be appreciated, thank you

more ▼

asked Nov 10 '11 at 10:56 AM

mehowe7 gravatar image

mehowe7
31 15 15 17

Well, Raycasts are usually very reliable. Are you sure you have your colliders set up properly? Are there other things interfering with them?

Nov 10 '11 at 10:58 AM syclamoth

You could always add a trigger collider thats larger then your actual objects, and then ray cast against those triggers instead of the actual colliders.

Nov 10 '11 at 04:06 PM DoktorAce
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Are you sure you have colliders setup? Why would a collider be unreliable at detecting a collision? That is effectively what you are doing with the raycast, sending out an invisible line and running a response dependant on what/if it hits. But there many ways to do this; through a RaycastHit or Debug.Log().

more ▼

answered Nov 10 '11 at 07:52 PM

portchris gravatar image

portchris
46 1 2 3

thankyou for replying the game is about clicking on different objects which are in close proximity of each other but they are all separate meshes. they are all tagged and all have mesh colliders. some detect the click easily and others you have to be very specific where you click. does camera angle have any effect on this? i have changed a couple to box colliders as this seems to be more effective on them. but others are not detecting the click at all.

Nov 11 '11 at 09:22 AM mehowe7

You should try looking at exactly where your colliders are going. I suspect that part of the problem is that a lot of them are interfering with each other, and one in front will stop the raycast from hitting the ones behind it.

Nov 11 '11 at 09:36 AM syclamoth
(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:

x1705
x1536
x225
x194
x161

asked: Nov 10 '11 at 10:56 AM

Seen: 882 times

Last Updated: Nov 11 '11 at 09:36 AM