Answers for "camera follow player unity"

3

unity camera follow

using UnityEngine;

public class Level3CameraFollow : MonoBehaviour
{
    // camera will follow this object
    public Transform Target;
    //camera transform
    public Transform camTransform;
    // offset between camera and target
    public Vector3 Offset;
    // change this value to get desired smoothness
    public float SmoothTime = 0.3f;

    // This value will change at the runtime depending on target movement. Initialize with zero vector.
    private Vector3 velocity = Vector3.zero;

    private void Start()
    {
        Offset = camTransform.position - Target.position;
    }

    private void LateUpdate()
    {
        // update position
        Vector3 targetPosition = Target.position + Offset;
        camTransform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, SmoothTime);

        // update rotation
        transform.LookAt(Target);
    }
}
Posted by: Guest on June-11-2021
2

camera follow player unity smooth

// CAMERA FOLLOW PLAYER - IN FIXEDUPDATE

Vector3.SmoothDamp(cam.position, transform.position + cameraOffset, ref cameraVelocity, CameraFollowSmoothTime);
cam.position = cam.position + cameraVelocity * Time.deltaTime;
Posted by: Guest on January-25-2021
9

camera follow

public Transform player;

    public Vector3 offset;

    void LateUpdate()
    {
        transform.position = player.position + offset;
    }
Posted by: Guest on June-11-2020
0

camera follow player unity

using UnityEngine;
using System.Collections;

public class Camera_Follow : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
private Vector3 newtrans;

void Start ()
{
    offset.x = transform.position.x - player.transform.position.x;
    offset.z = transform.position.z - player.transform.position.z;
    newtrans=transform.position;
//not taking y as we wont update y position. 

}

void LateUpdate ()
{
newtrans.x= player.transform.position.x + offset.x;
newtrans.z= player.transform.position.z + offset.z;
transform.position = newtrans;
}
}
Posted by: Guest on June-15-2021
0

Camera follow player unity

using UnityEngine;
using System.Collections;

public class Camera_Follow : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
private Vector3 newtrans;

void Start ()
{
    offset.x = transform.position.x - player.transform.position.x;
    offset.z = transform.position.z - player.transform.position.z;
    newtrans=transform.position;
//not taking y as we won't update y position. 

}
void LateUpdate ()
{
newtrans.x= player.transform.position.x + offset.x;
newtrans.z= player.transform.position.z + offset.z;
transform.position = newtrans;
}

}
Posted by: Vionix on April-12-2022

Code answers related to "camera follow player unity"

Browse Popular Code Answers by Language