Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Camera follow using Rigidbody2D brakes on platform

Discussion in '2D' started by Schumaker, Feb 16, 2021.

  1. Schumaker

    Schumaker

    Joined:
    Jul 14, 2016
    Posts:
    40
    Hello,

    I am using a simple script to do the camera follow, to achieve the smoothness I want, I do the camera movement based on the Rigidbody2D of the player.

    // omitting parts
    // float speed = 3f;
    // float moveSpeed = rb.velocity.magnitude > speed ? rb.velocity.magnitude : speed;

    The problem is, when the player is in a movement platform, I need to make the player children of the platform for him moves according to the platform. So no force is added to the Rigidbody2D then the camera does not
    move. Any tips?

    Thanks is advance,
    Hudson Schumaker
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    80
    Hi @Schumaker, maybe you could store the previous world position in your script and calculate the velocity based on current world position of your object
    Code (CSharp):
    1. var currentVelocity = (currentWorldPosition - previousWorldPosition) / Time.deltaTime
    Have you tried using Cinemachine? It supports 2D orthographic cameras, it's very flexible and allows you to work in a more procedural way
    https://learn.unity.com/tutorial/cinemachine#5c7f8528edbc2a002053b4f0
     
  3. Schumaker

    Schumaker

    Joined:
    Jul 14, 2016
    Posts:
    40
    thanks for the help. I will check it out. I have to say using the Rigidbody2D speed I achieve a very smooth camera.
     
unityunity