Forum begins after the advertisement:


[Part 1][Feature] Smooth transitioning camera

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 1][Feature] Smooth transitioning camera

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #13420
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Sharing code by @Seshua87 in YouTube on getting a smooth transitioning camera:

    For anyone wanting a smooth transition for the camera here’s how I wrote mine. Not sure if he covers this later, as I haven’t made it that far into the series. :)
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class CameraMovement : MonoBehaviour
    {
        [SerializeField]
        private Transform target;
        [SerializeField]
        private Vector3 offset;
        [SerializeField]
        private float cameraSmoothingAmount = 25.0f; //For the camera transition smoothing.
    
        private Vector3 currentVelocity; //For the camera velocity reference.
    
        private void Update()
        {
            //Set the targets position and offset to a variable
            Vector3 targetPosition = target.position + offset;
            //Smoothly transition the camera by using the SmoothDamp function. Be sure to add a Vector3 variable above for the referenced velocity.
            //Also create a float for controlling the smoothing amount. I find 25 is good starting point.
            transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref currentVelocity, cameraSmoothingAmount * Time.deltaTime);
        }
    }
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: