Hi everyone. Im new to scripting. Im writing this code for my player. It moves great, it jumps well, and ive attached the camera to my player to be a child of it, but the problem is that i dont want the camera to follow the player when he jumps. Actually i want the camera to remain on where it is right now on its y axis but still be a child of my player and follow it on x axis and i have to mention that its a 2d game and ive attached this script to my player. I really need your help. tnxx alot…
var playerSpeed : int;
var jumpHeight : int;
function Update ()
{
//1- childing the main camera to the player, so that it will follow the player transform.position
// getting the transform of the main camera and put it in a new var.
var cameraTransform = Camera.main.transform;
// making the camera child of the player.
cameraTransform.parent = transform;
//2- moving the player...
// amount to move the player
amtToMove = playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
// transform/translate the movement of the player...
transform.Translate(Vector3.right * amtToMove);
//3- player jump
// player can countinusly jump when you hold the space. if its transform position in y axis is equal to 0.73(on the ground)
if ( Input.GetKey("space") && transform.position.y == 0.73)
{
amtToJump = jumpHeight + Time.deltaTime;
transform.Translate(Vector3.up * amtToJump );
}
// now here i want to add something that can prevent the camera to follow my player when he jumps! and i need your help :(
}