Hi!
I am looking for a camera setup that allows me to shift camera slightly above the object(so that i can view object’s top portion) when i click over near its upper part(over round object).
The camera needs to move just at y axis and must always be looking at gameobject, always keeping a distance of 3 units at z axis.
To keep a specific distance at the z-axis, put the camera there (since you said we only need to move the y-axis, i’m assuming you dont want to move a half-circle while going up). To make the camera always look at the object, use LookAt() at the bottom of what you are doing each frame. Now we basically only need to adjust the y-axis position of your camera.
First of all, you said you that you want to evaluate after you click on an object, and then move the camera based on that. When you detect a left mouse button click, cast a ray through the camera at the position of your mouse. This ray will return us informations, such as the hit object. If the hit object is the correct object, we can now try to think about what it means to “click on the upper part on a round object”, because that’s a bit subjective.
First and foremost, the ray you cast will return you the normal of the hit location. A normal is a vector always pointing upwards from a mesh surface. Thus, using the normal, we can determine where on the sphere you clicked.
I would probably just compare the normal with Vector3.up using Vector3.Angle() and then accept the input, if the angle is below some predefined threshold. This effectively means that the angle you allow determines the size on top of the sphere that’s considered “top”.
After all those conditions were met (leftclick, on right object, on what you consider top), simply move the y-axis of your camera upwards - either by teleporting it, or by lerping it to a new position over multiple frames.
Hey, Your idea was may be right but I was facing difficulty getting behavior I wanted. I got the exact behavior i wanted just by rotating and re-positioning objects in front of camera. it just illusioned the right behaviour i needed. But thanks for your kind response i may still need some parts from your advise.
Thank You!