- Home /
Camera, Offsetting the Transform.LookAt
Hey People, ive got a very basic script for my Main camera to follow my player. im creating a 2.5D platformer and im doing allot of fine tuning atm.
here is my code
var Target : Transform;
var distance = 5;
function LateUpdate () {
transform.position = Target.position + Vector3(0, distance, -30);
transform.LookAt (Target);
}
At the moment the ground/floor, takes up 50% of the screen real-estate. I want it to take up much less, is there a simple command i can use to do this? i have fiddled around with the (0, distance, -30) part but it isn't relevant.
Any Suggestions?
Hey davidc your question just keep popping up in my mail inbox :)
Hm. Does it really not change when you put something else as the distance variable like 100.
If not you could try to add something like
transform.position = Target.position + Vector3(0, 0, -30) + (Vector3.up * height); //I called it height not distance here because it makes more sense to me
Answer by robertbu · May 02, 2013 at 08:24 PM
Your problem is the transform.LookAt(). You can move the camera up and down, but if you use a LookAt(), the camera is going to be tilted so that you character is in the center of the screen. How you solve this will depend on how you want camera to follow the character. As a start, take out the transform.LookAt() and adjust the Vector3(0,distance,-30).
AHHH, thank you guys, it was the transform.lookat that was the problem, i didn't realize i didn't need it for what im doing. thank you
Answer by angelonit · Mar 02, 2014 at 05:15 AM
I had this problem in a 3D environment and I found the solution to be to move the camera after the lookat:
Vector3 lokat = camTarget.position; transform.LookAt(lokat); transform.position+=Vector3.up*0.9f;