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
Your simplicity is amazing. I love this series
Thanks for your kind feedback 😊
Love your videos! Thank you & I hope you keep going with these!
Thank you so much 😊
always useful stuff, hope you doing great
Thank you very much, I'm glad you liked it. I hope you are doing well too 😊
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);
}
}
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 🙏
man you are great
thank you so much 😊
Bro u earned one sub from me.
thanks for the tutorial...
Thank you so much 😊 and welcome 🖐
How about using cinemachine ? Is this the better way or would you prefer cinemachine?
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?
Thank you brother
Amazing tutorial, everything works well - but why not use cinemachine instead?
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.
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?
delete and re-add camera object. then redo all the steps
wouldn't it be easier to just use cinemachine?
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?
solution: replace LateUpdate with update in camera controller script
it works in my case
I'm glad you solved the problem.
How to change camera size using code?
thanks you
Thank you too!
What's the difference between normal camera movement and this script
This way you can ensure a smoother tracking.
You can see the difference by trying both methods.
my character can't be seen
Vector3' không chứa định nghĩa cho 'smoothDamp' T-T
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ể 😊
How to fix stuttering
Write camera movement code in LateUpdate
Reduce smoothTime
Or better yet: use FixedUpdate instead of LateUpdate, now the updates won´t be reliant upon your fps