I’m trying to move the camera by clicking & dragging.
I have found several scripts to do this, but none of them give me the exact result I want.
What I want is that, if a specific object is beneath the mouse when I start dragging, I want the same object to stay exactly under the mouse as I drag it around.
None of the examples I found have this feature.
This is a 2D project so I’m using the camera in orthographic mode.
It sounds like you actually want two separate modes of dragging, based upon your click starting on an object:
dragging the camera view around
dragging an object around, and then letting the camera try to watch it
If you do #2 above by trying to simultaneously move the object AND the camera, you are going to get feedback because the world position of the object will change, then the effective world position of your click will change when the camera moves, etc. etc.
Thinking about it, you might still have issues… hm… you would need to notice mouse world position differences AND you would need to back-patch those differences each time the camera moves…
No, maybe I didn’t express myself correctly, but I’m just trying to move the camera.
All other game objects should stay in the same world position, they only appear to move in the screen because the camera will be moving.
The script I posted is attached to the camera. No other game object is moving at the moment.
Ok, I don’t know why the above code was not working, but I found an alternate way to do it and it’s working perfectly.
Here’s the code in case anyone would like to use it.