- Home /
3d platforming Camera
I've been working on this camera rig were the camera rotates and follows around the player. I've already got the rotation taken care of in another script. What I've been looking how to do is trying to get the rig to only follow the player on the x and z axis using the players exact position. But i can't seem to find to call upon one of the transforms positions. the next part would be a smooth follow Y axis where you can see the player jump up and down the screen like you would see in Mario 64 and other classic 3d platformers.
I have been using this for the basic uses so far
transform.position = player.position;
And if you show any examples of code please show it in c# other wise its fine Ill convert it.
Answer by Nabeel Akhtar · Jun 01, 2015 at 04:52 AM
Add these line of code and they will handle all
private Vector3 velocity = Vector3.zero;
void Update(){
camera.transform.position = new Vector3 (player.transform.position.x, Mathf.SmoothDamp (camera.transform.position.y, player.transform.position.y, ref velocity.y, 0.3f),player.transform.position.z);
}
thanks works great had to modify it a bit though if (cameraSpeed>0){ cameraSpeed -= Time.deltaTime*ReachTime; } else { cameraSpeed = 0; } } else { cameraSpeed = camSpeed; } transform.position = new Vector3 (player.transform.position.x, $$anonymous$$athf.SmoothDamp (transform.position.y, player.transform.position.y, ref velocity.y, 0.03f* cameraSpeed), player.transform.position.z);