- Home /
Ease in transform.LookAt() - keep other target within camera boundaries
Suppose you let the user click on any point in a "grid plane" to look at (transform.LookAt(Input.mousePosition)
). But, you want to keep a target object within view of the camera.
How would you check that the new lookat view keeps that target object within bounds of the camera? Also, is there a way to ease in the transform.lookat? Would using Lerp be appropriate, or should a curve be used?
Answer by The_r0nin · Dec 22, 2010 at 04:15 PM
To "ease" the rotation, you can Lerp between your (transform.forward * Vector3.Distance(transform.position,target.transform.position)) and your target.transform.position [so you have equal length vectors... you could also normalize]. Then set transform.LookAt() to the resultant vector.
You can use Renderer.isVisible to find out if the camera can see the object, but you'd be better off just setting a position that the camera zooms to that will keep both in view (requires a little math, but you can figure out the angle needed to make the camera equidistance from both target and point).
Your answer
Follow this Question
Related Questions
Best way to tell which object(s) are being looked at? 3 Answers
When moving camera I like my circle Plane look at cam. 0 Answers
Object as far Z as it can 0 Answers
How to make an object to look at Raycast Hit Point? 1 Answer
How to use js to add an camera target texture to an objects's renderer.materials 2 Answers