Unity 2D SMOOTH CAMERA FOLLOW Tutorial | Unity 2D Platformer Tutorial #3

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.พ. 2025
  • In this Unity 2D tutorial we're gonna do Smooth Camera Follow .
    We will use SmoothDamp Method for Camera Follow system.
    How To Clamp or Limit Camera Movement ?
    Sprites : drive.google.c...
    Enjoy the video ☕
    ----------------------------
    🖐 Hi Game developer
    Welcome to Rehope Games I'm Murat
    I share unity tutorial videos on my channel. if you want to make a game with unity (especially 2d platformer game), the videos here will definitely interest you.
    ----------------------------
    #unitytutorials, #unity2d, #unity2dplatformer

ความคิดเห็น • 36

  • @Pixelgraft
    @Pixelgraft ปีที่แล้ว +1

    Your simplicity is amazing. I love this series

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Thanks for your kind feedback 😊

  • @DariiaPlaysMusic
    @DariiaPlaysMusic ปีที่แล้ว +1

    Love your videos! Thank you & I hope you keep going with these!

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Thank you so much 😊

  • @totojatiwijayanto4501
    @totojatiwijayanto4501 ปีที่แล้ว +1

    always useful stuff, hope you doing great

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Thank you very much, I'm glad you liked it. I hope you are doing well too 😊

  • @laszlo-csabatorok7638
    @laszlo-csabatorok7638 ปีที่แล้ว +1

    hello,
    Hope you are well.
    I really like your videos, up until now everything was clear to me, but in this video I got into some trouble.
    After I added this to the camera controller the position of the camera moved in every direction. Z was not -10 anymore, the position of x and y changed also. So I could not see the player anymore.
    [Header("Axis Limitation")]
    public Vector2 xLimit;
    public Vector2 yLimit;
    targetPosition = new Vector3(Mathf.Clamp(targetPosition.x, xLimit.x, xLimit.y), Mathf.Clamp(targetPosition.y, yLimit.x, yLimit.y) - 10);
    Did I do anything wrong? Before I add this lines was working perfect. Bellow is the full script
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class CameraController : MonoBehaviour
    {
    Transform target;
    Vector3 velocity = Vector3.zero;
    [Range(0,1)]
    public float smoothTime;
    public Vector3 positionOffset;
    [Header("Axis Limitation")]
    public Vector2 xLimit;
    public Vector2 yLimit;

    private void Awake()
    {
    target = GameObject.FindGameObjectWithTag("Player").transform;
    }
    void LateUpdate()
    {
    Vector3 targetPosition = target.position + positionOffset;
    targetPosition = new Vector3(Mathf.Clamp(targetPosition.x, xLimit.x, xLimit.y), Mathf.Clamp(targetPosition.y, yLimit.x, yLimit.y) - 10);
    transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
    }

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      targetPosition = new Vector3(Mathf.Clamp(targetPosition.x, xLimit.x, xLimit.y), Mathf.Clamp(targetPosition.y, yLimit.x, yLimit.y), - 10);
      Add comma (,) before (-10)
      And Thank you so much I'm great 😊
      I wish you success in your game project 🙏

  • @Zero-bn4nc
    @Zero-bn4nc 2 ปีที่แล้ว +1

    man you are great

    • @RehopeGames
      @RehopeGames  2 ปีที่แล้ว

      thank you so much 😊

  • @purple_larry
    @purple_larry ปีที่แล้ว +1

    Bro u earned one sub from me.
    thanks for the tutorial...

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Thank you so much 😊 and welcome 🖐

  • @ObitoUchiha-zu9yn
    @ObitoUchiha-zu9yn 10 หลายเดือนก่อน

    How about using cinemachine ? Is this the better way or would you prefer cinemachine?

  • @TaleArtist
    @TaleArtist 10 หลายเดือนก่อน

    I am getting this error:
    Assets\Scripts\CameraController.cs(5,14): error CS0101: The namespace '' already contains a definition for 'CameraController'
    is there any way to fix this?

  • @VarunAiyar
    @VarunAiyar 7 หลายเดือนก่อน

    Thank you brother

  • @wormholeinteractive
    @wormholeinteractive ปีที่แล้ว +1

    Amazing tutorial, everything works well - but why not use cinemachine instead?

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Thanks a lot 😊
      yes cinemachine is a good method..
      I made this video to teach basic logic.
      actually i use a more advanced camera follow algorithm in my own games. Maybe I'll show it later.

  • @kirillkolpin3030
    @kirillkolpin3030 ปีที่แล้ว

    i have problems: i hsave script of Camera controller. I did all by your steps -> all working, then when i forgot to save file all disappeared, but scripts are remained. Then when i redo all of that, camera controller script stopped working. Like i repaced main camera position, but when i starting game camera didnt following the player. What should i do?

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      delete and re-add camera object. then redo all the steps

  • @Kitoniarz
    @Kitoniarz 6 หลายเดือนก่อน

    wouldn't it be easier to just use cinemachine?

  • @Pashdet
    @Pashdet 2 ปีที่แล้ว

    I have a problem with this guide. the camera is chasing the player, but when moving the camera along the x-axis, stutters are visible
    any solutions?

    • @Pashdet
      @Pashdet 2 ปีที่แล้ว

      solution: replace LateUpdate with update in camera controller script
      it works in my case

    • @RehopeGames
      @RehopeGames  2 ปีที่แล้ว

      I'm glad you solved the problem.

  • @AnkitPatel04
    @AnkitPatel04 ปีที่แล้ว

    How to change camera size using code?

  • @gamoe
    @gamoe 2 ปีที่แล้ว

    thanks you

  • @tharunsai2543
    @tharunsai2543 ปีที่แล้ว

    What's the difference between normal camera movement and this script

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      This way you can ensure a smoother tracking.
      You can see the difference by trying both methods.

  • @tishaprnucedteasha
    @tishaprnucedteasha 10 หลายเดือนก่อน

    my character can't be seen

  • @lorihihi5171
    @lorihihi5171 ปีที่แล้ว

    Vector3' không chứa định nghĩa cho 'smoothDamp' T-T

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      xin chào,
      bạn có thể giải thích chi tiết câu hỏi của mình không? bằng tiếng anh nếu có thể 😊

  • @obuaebuka
    @obuaebuka ปีที่แล้ว

    How to fix stuttering

    • @RehopeGames
      @RehopeGames  ปีที่แล้ว

      Write camera movement code in LateUpdate
      Reduce smoothTime

    • @adrianvargas1380
      @adrianvargas1380 9 หลายเดือนก่อน +1

      Or better yet: use FixedUpdate instead of LateUpdate, now the updates won´t be reliant upon your fps