I have a cube with 10*10 cubelets on each side. it rotates with mouse drag. I have added colliders for each cubelets. When I click on a cubelet the camera should zoom into the cubelet filling the screen with that cubelet.(like how double clicking on google earth works)Any ideas on how I can do that.
if you are using a Camera in perspective mode, you can just change the position.z of the camera until the cubelets fill the screen.
Add the variable so you can see if from the inspector so you can experiment and get the correct value:
var zoom : float= -10;
function Update(){
transform.position.z = zoom;
}
Thank you for the reply. but that would work only if the cubelet is in the center of the screen. what if I select the corner cubelet. then the camera must align with axis with the cubelet first, then zoom in right ?
Yes you are right, set the x and y posision to that of the cubelet aswell then. so it zooms in and moves to the position of the cubelet. This way the center of the cubelet will be in the center of the screen.
not tested it but you could try setting the rotation to Quaternion.identity on GetMouseButtonUp. Oh and can you mark the answer if it fixed your issue :D thanks!
Thank you for the reply. but that would work only if the cubelet is in the center of the screen. what if I select the corner cubelet. then the camera must align with axis with the cubelet first, then zoom in right ?
– KuruviYes you are right, set the x and y posision to that of the cubelet aswell then. so it zooms in and moves to the position of the cubelet. This way the center of the cubelet will be in the center of the screen.
– thaiscorpionnot tested it but you could try setting the rotation to Quaternion.identity on GetMouseButtonUp. Oh and can you mark the answer if it fixed your issue :D thanks!
– thaiscorpion