- Home /
Camera problem
I want the camera to be over the level after I press space in a specific area. But when I play the game, go to the area and hit space...it's position goes somewhere else (can only see white, the color I chose to be in the background).
does the error come from that I fixed the cameras position to the player?
here is the code:
void OnTriggerStay(Collider other) {
//print("VI ER PO GONG!");
if(Input.GetKey("space"))
{
//print("VI E LADDADE!");
Camera.main.transform.Translate(100,82,26);
}
}
Answer by japanitrat · Sep 12, 2011 at 10:48 AM
Translate moves the transform relative to its previous position. When the key is pressed (more than one frame) the camera moves, moves, moves, moves, and moves again. Either you use absolute coordinates (transform.position) or you try it with Input.GetKeyDown, which is only fired once
I tried changing the code to:
camera.main.transform.position(100,82,26)...but I only get an error =/
Yes, cause position is an instance of Vector3 and not a method. Try this:
camera.main.transform.position = new Vector3(100, 82, 26);
would you please position your camera at these coordinates and check if it is also white if you manually position it?
ah....now I see the problem. the position is right, but not the rotation. Now I only need to figure out how to change position and rotation
Answer by Ludiares.du · Sep 12, 2011 at 10:49 AM
In your script you're moving the camera, not positioning it. Instead try using:
Camera.main.transform.position(100,82,26);
I tried with position, but it only gets an error reading: Unityengine.Transform.position cannot be used as a method or delegate
Your answer
Follow this Question
Related Questions
Adding y position? 4 Answers
RTS Camera movement wrong after rotation 1 Answer
How can i freeze the camera in Google cardboard? 0 Answers
throwing a ball camera position changes 0 Answers