Question by
dimitrakis1992 · Jan 13, 2017 at 09:59 AM ·
c#cameraplayer
Change Camera Position
Hello to everyone.I try to build a 2D game and i have a problem with the camera.Now the camera follows the player and when the player is up(jump) camera follows him and i don't want this.I want from the camera to be in center and follow the player and when the player jump to remain in center.How to do that?Please help me.I know little about coding.Sorry for my english.Thank you very much
My code is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camerafollow2DPlatformer : MonoBehaviour {
public Transform target;
public float smoothing;
Vector3 offset;
float lowY;
// Use this for initialization
void Start () {
offset = transform.position - target.position;
lowY = transform.position.y;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
if (transform.position.y < lowY) transform.position = new Vector3 (transform.position.x, lowY, transform.position.z);
}
}
Comment
Your answer
Follow this Question
Related Questions
What this error? 0 Answers
Camera looking at the player at an angle 1 Answer
Problems with rotating the player on the Y axis C# 0 Answers
Is there a way to prevent camera from falling even though it is a child of the player? 0 Answers
How do I make my player's movement relative to Main Camera's direction? 1 Answer