Hi all, I'm alway fighting with the 3dsMax animation fbx import with Unity, but I'm actually facing a new problem with camera... I've try to use the Camera Focus, Scrolling and Attributes from Unity example, but without success. Unfortunately when I clic play button my camera leave the scene and looking anywhere except my target I don't know why, probably due to my fbx scale import problem :/ So I try to write a new script for my cam, because due to the use of the plateformerController for my Heros, it's impossible to simple attach a camera to the player... it's a 2D/3D game and in this case the camera is alway changing of Z position when the Heros go right or left... I want my camera to follow my heros (Target) in X and Y axes, but never move on the Z axe, who could be Z.++7 for example. I've try to write a little java script and my camera follow my player transform. but I would like my camera always in Z -7 Could someone help me ?? here is the beginning of my script : Code (csharp): var target : Transform; function Update() { GameObject.Find("Main Camera").transform.position = target.position ; transform.LookAt (target); } Maybe this is a easy code for many of you, but I'm a big noob in code :/ Thanks for your help.
Can you post the script you were originally using? It's not likely that the object's scaling would stop the camera from looking at it correctly.
Hi Andy unfortunately I didn't find any kind of code corresponding of my project except those of the Unity example. In this code for me : //I create the variable target and get all her transform infos var target : Transform; //I use Update to use function every frame function Update() { //I fond the object mainCamera and apply target transform to camera transform GameObject.Find("Main Camera").transform.position = target.position ; //finally I ask my camera to lookAt the Target var... transform.LookAt (target); } I have try many thing as Vector3 to use only x and y information from var target but I fail by using this code :/ I would like my cam always stay on the same Z -7 position and only move in x and Y axe following the target... Could you help ?
Try changing the line to:- Code (csharp): Camera.main.transform.position = target.position - Vector3.forward * 7.0;
It's probably not working because you are setting the position of the camera to be identical to what it's supposed to be looking at. That would be like trying to look inside your own eyeballs!