|
So I'm building a simple platform game (think something like Mario, prince of persia, take your pick etc). The camera follows the player through the level, simply by being a child of the player's object. The problem is that I made my character turn back and forth. I.E. if you are facing right and hit the left key, the character object is turned 180 degrees. That works great, except that the camera (being a child of the the Player) also turns 180 degrees! Is there a way I can lock the camera's rotation, or just have it follow the player's movement on the X and Y axis, without taking the player's rotation? I can think of some bizarre solutions that might work, but I'm betting there is a cleaner, more efficient solution then for example un-parenting the player from the camera before a flip, and then re-parenting the player to the camera afterward. Thanks for all your help, having a blast with Unity :)
(comments are locked)
|
|
Easiest way would be to unparent the camera. And throw something similar to the following in your update. int DistanceAway = 10; Vector3 PlayerPOS = GameObject.Find("Player").transform.transform.position; GameObject.Find("MainCamera").transform.position = new Vector3(PlayerPOS.x, PlayerPOS.y, PlayerPOS.z - DistanceAway); This will keep the camera bound the the players X and Y coordinates while placing the camera 10 meters from the player. Then all you have to do is the the cameras rotation in the editor. That or for the rotation use .LookAt(target); with the player being the target. Please note that "Find()" is a very expensive operation.
May 05 at 01:30 AM
Nepoxx
(comments are locked)
|
|
Just put this script on your Main Camera. Set the cameraOrientationVector to how far from your character you want it to be. And tilt the camera in scene view for the angle.
(comments are locked)
|
|
var camTarget:Transform; function Start () { } function Update () { transform.LookAt(camTarget); }
(comments are locked)
|
|
Put this on the camera: It forces the rotation. I dont know if this is the best way of doing this but works.
(comments are locked)
|
1 2 next page »

hi LeviS, got any improvement on this??!