#Background moving slower than player?

1 messages · Page 1 of 1 (latest)

tawny ingot
#

Hey Im making simple game where you move as ship and mine asteroids.

I wanted to make my background move slower than player so its "depth" effect to it as you can see on the video if its just on player all the time it looks weird and if its not moving at all its also weird.

So basicly how to make background follow player, not rotate, but move slower than him so it builds some offset.

#

I used this script from codemonkey video:
https://www.youtube.com/watch?v=wBol2xzxCOU

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

public class Space : MonoBehaviour
{
    [SerializeField] private Vector2 parallaxEffectMultiplier;

    private Transform cameraTransform;
    private Vector3 lastCameraPosition;

    private void Start() 
    {
        cameraTransform = Camera.main.transform;
        lastCameraPosition = cameraTransform.position;
    }

    private void LateUpdate() 
    {
        Vector3 deltaMovement = cameraTransform.position - lastCameraPosition;
        transform.position += new Vector3(deltaMovement.x * parallaxEffectMultiplier.x, deltaMovement.y * parallaxEffectMultiplier.y);
        lastCameraPosition = cameraTransform.position;
    }
}

✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=wBol2xzxCOU
Let's make a simple script to achieve an awesome Infinite Background Parallax Scrolling Effect!

If you have any questions post them in the comments and I'll do my best to answer them.

🔔 Subscribe for more Unity Tutorials https://www.youtube.com/chan...

▶ Play video