Sign in to follow this  
Weng

How to identify 3D scene objects with a mouse click?

Recommended Posts

I am developing a multiplayer point and click game. How do I correctly identify the scene object which is being clicked on? Currently, I use ray picking to identify the object being clicked. The first object which is intersected by the picking ray is taken to be the object which is clicked. However, the problem is that if there is a player character standing in front of that object, the result will be inaccurate as the ray intersects the character first even if the object is clicked. Since the picking ray could intersect through several scene objects, how do I identify which is the actual scene object which is being clicked? Or is there another method of identifying clicked objects?

Share this post


Link to post
Share on other sites
Just curious: If a character is standing in front of an object, and the player clicks in such a way as it intersects the character first and then the object, then how do you determine that the object is clicked and not the character? [not from a technical standpoint, but from a 'here is what I want from my game' high level standpoint]. In other words, why is it wrong to say that the player clicked on the character, which is the first thing that the ray intersects, instead of saying that the player clicked on the object, which the player occludes?

Share this post


Link to post
Share on other sites
Hmm...Using texture colours would seem a little risky and difficult as it would require every texture to have a unique colour.

Other than colours of the texture, are there other ways to correctly identify a scene object which is being clicked on?

Share this post


Link to post
Share on other sites
I've used the ray picking which you've used.

Also, from the first post, it sounds like your game is isometric?

One solution could be to give characters a "lower priority" for picking. IE, all objects have priority 0, and characters have priority 1. If you have two ray collisions, select the object with the lowest priority.

Obviously, that could be really really wierd if you have a character who is nearby, and an object 100 meters back, and it selects the object. You could make the priority to some scaling of the length so that you can get it slightly better (ie, the length of all objects of priority 0 is 1x their length, objects of priority 1 are 1.5x their length... So if you have a character and an object with the character slightly occluding the object, and you really want the object, if you grab the object with shortest ray, then you will get the object many times... You could tweak those values if you want). I don't believe it would be the best solution though.

Hopefully this gives some ideas of sorts!

[Edited by - Iced_Eagle on November 24, 2008 2:34:52 AM]

Share this post


Link to post
Share on other sites
Can't you check the distances of each object from the camera / screen? The closest object or character to the camera is the one you pick.

To do this you need to check every object and not just the first one you find so it's important to minimise the checking done on objects not shown in the current display or too far away to be considered pickable.

Share this post


Link to post
Share on other sites
Quote:
Original post by Weng
However, the problem is that if there is a player character standing in front of that object, the result will be inaccurate as the ray intersects the character first even if the object is clicked.

Since the picking ray could intersect through several scene objects, how do I identify which is the actual scene object which is being clicked?

Or is there another method of identifying clicked objects?

This isn't a problem with the ray-picking itself, but rather the higher-level logic used to determine what the user really "wanted" to click on (which is what Drigovas alluded to). Unfortunately, we really can't help you much here since that logic will depend on your game. If you have several objects being returned from the picking code then I imagine that you would implement some sort of filter to eliminate obvious false-positives (i.e. the user didn't want to select the tree, he wanted to select the unit behind the tree) and then go from there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jon Alma
Can't you check the distances of each object from the camera / screen? The closest object or character to the camera is the one you pick.

To do this you need to check every object and not just the first one you find so it's important to minimise the checking done on objects not shown in the current display or too far away to be considered pickable.


Well that's part of ray picking, so I assume he's done that, and his problem is just that he would rather select an object slightly further than the closest object as it would make more sense.

As Zipster said though, it's really game dependent on what you do from just ray picking.

Share this post


Link to post
Share on other sites
Quote:
Original post by Weng
Hmm...Using texture colours would seem a little risky and difficult as it would require every texture to have a unique colour.

Other than colours of the texture, are there other ways to correctly identify a scene object which is being clicked on?


I didn't mean to render the objects with their actual texture, but a random color. You could even use their bounding volumes, or a lower level of detail of the geometry. Also you wouldn't have to render everything, only the selectable objects. Finally if the scene is static, at least the selectable objects and camera, you won't have to update the texture every time the player clicks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this