camera follow player unity 2d

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    //Object you want to follow
    public Transform target;
    
    //Set to z -10
    public Vector3 offset;
    
    //How much delay on the follow
    [Range(1, 10)]
    public float smoothing;

    private void FixedUpdate()
    {
        Follow();
    }

    void Follow()
    {
        Vector3 targetPosition = target.position + offset;
        Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.fixedDeltaTime);
        transform.position = smoothPosition;
    }
}

3.5
6
Zwlayer 125 points

                                      public Transform player;  public Vector3 offset;    void Update ()   {      transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z); // Camera follows the player with specified offset position  }

3.5 (6 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to make a camera follow an object in unity 3d unity camera follow player 3d how to make main camera follow player unity 2d script camera follow player unity camera follow script unity 2d how to make 2d platformer camera follow player unity unity script camera follow player 2d unity 2d camera follow rigidbody unity camera follow 2 objects camera follow player unity 2d top down unity - camera follow player 2d have camera follow player unity 2d unity 2d make camera follow player ssmoothly unity 2d make camera follow player slowly hoq to get camera to follow object in unity 2d unity camera follow player 2sd camera follow smoth player unity 2d 3d camera follow player script unity unity 2d get camera follow player camera follow smoth player unity 2d make camera follow player unity2d how to make the camera follow an object unity 2d how to get cam to follow player in 2d unity 2d follow camera unity follow camera unity 2d how to make camera2d follow object with script unity how to make the main camera follow our player in 2d in unity unity 3d make camera follow player unity camera follow player 2d brackeys how to have the camera follow a 2d character in unity unity asset store camera follow player 2d how to get the camera to follow the player in unity 2d unity camera follow player smooth 2d script camera follow player unity 2d follow player in 2d unity camera follow plyer in unity 2d script to let camera follow player in unity 2d unity 2d camera follow player script download How to make a 2D follow cam in unity make the camera follow 2d unity unity 2d camera follow how to make camera follow player unity 3d unity 2d camera follow script get camera to follow 2d player unity camera follow script for unity 2d camera follow player 2d unity unity 3d camera follow player camera to follow player unity 3d how to get camera to follow player unity 2d unity 2d camera followingh player player follow camera unity simple 2d camera follow unity unity make the camera follow player make camera follow object in unity follow player camera unity camera follow ball unity 2d unity 2d camera horizontal follow player how to make the camera follow an object unity 3d make camera follow player unity camera follow player unity 3d set camera to follow player unity 3d unity make camera follow player how to have the camera follow player untiy 2D unity 2d follow player unity 2d follow camera how to have camera follow player unity camera follow player c# 2d camera follow player unity2d camera follow player unity main camera follow character unity 2d how to make the camera follow the player in unity 3d follow player camera unity 2d how to make 2d camera follow player unity how to make camera follow you unity 2d how to make camera follow an object unity 2d make camera follow player unity 3d how to make camera follow player unity 2d make the camera follow the player unity make camera follow player unity 2d cinemachine how to let your camera follow the plyer unity 2d how to make camera follow the player in unity 2d how to make camera follow the player in unity 2 main camera follow character unity 2dù camera follow player 3d unity camera follow the player unity 2d camera follow script unity Unity Top Camera Follow Script 2d unity camera follow 2 players unity 2d how to make camera follow the character simple script for camera to follow player unity 2d unity 2D game camera follow player unity camera follow player 2d camera follow character unity how to make the camera follow the player in unity how to make camera follow player unity camera follow player unity 2d camera follow player unity 2d script 2d camera follow unity unity c# camera follow player game 2d camera follow unity 2d make camera follow player unity 2d unity how to make camera follow player 2d only x unity how to make camera follow player 2d unity 2d ik follow camera unity camera follow script 2d 2d camera follow make the camera follow an object unity how to make the camera follow the player in unity 2d how to get a camera to follow a object in a 2d game unity how to make a camera follow an object in unity 2d unity make camera follow player 2d camera follow player unity in 2d unity camera follow player 2d 2d game camera follow player unity 2d camera follow player how to follow camera in unity 3d how to get a new main camera in unity 2d camera follow 2d unity how to set camera to player unity 2d
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source