Moving an Object with the Camera

I am working on a portion of a game that I would like to:

select a specific object

lift that object to the center of the camera

when I move the camera the object stays in the center

then when I tell it to, it lowers that object to the ground or on an object, whatever is required.

I have accomplished selecting the object when it's in view of the camera

using a Ray, which I don't find particularly gratifying since I've not discovered how to widen the "beam" of the ray – it seems like the object must be in the center of the screen to begin with… I've got more research to do.

I can lift that object (simple y++, etc).

Does anyone have any ideas about putting the object into the center of the camera?

Then, setting the location based on the direction of the camera as I move it?


I do exactly that in my (unreleased) system. I use a tool-based approach. The tool is connected to the mouseInputListener, mouse events are routed to the tool object. The tool can pick an object. It remembers the current distance of the camera to the object. When the camera is moved (by mouse), the tool gets a new camera pick ray in absolute space. The tool calculates the point on this ray with the saved distance to the camera, and sets the position of the picked object to this position.

I could attach the code to this, but it would definitely not make sense to you without seeing the rest of my application

That sounds like what I'm looking for.

I'll see if I can replicate it.