Forum begins after the advertisement:


[Part 1] errors on velocity and victor

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 1] errors on velocity and victor

Viewing 2 posts - 21 through 22 (of 22 total)
  • Author
    Posts
  • #17920
    Ser Apustaja
    Level 6
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    If the camera is still moving away from the player despite following the previous suggestions, let’s troubleshoot further:

    1. Check Offset Values: Make sure that the offset values are set correctly. If the y value is too high, the camera will appear to move away from the player. For example, if your player is at (0, 0, 0), an offset of (0, 5, -10) will place the camera above and behind the player.

    2. Camera Position Reset: Sometimes, the camera’s initial position may not be set correctly. Try resetting the camera’s position in the Scene view to ensure it starts at the expected location relative to the player.

    3. LateUpdate Method: Make sure you’re using LateUpdate() for the camera follow logic. This ensures that the camera position updates after the player’s position updates.

    4. Player’s Position Changes: Check if there are any scripts affecting the player’s position that may be causing erratic movement. Ensure that the player is not being moved in a way that would push it away from the camera.

    5. Debugging Position: Add some debug statements in your CameraFollow script to log the camera and player positions:

      void LateUpdate()
      {
          Vector3 targetPosition = player.position + offset;
          transform.position = Vector3.Lerp(transform.position, targetPosition, followSpeed);
      
          Debug.Log($"Camera Position: {transform.position}, Player Position: {player.position}");
      }
    6. Camera Clipping Planes: If the camera is moving too far away, check the camera’s clipping planes. Ensure the Near and Far clipping planes are set correctly; although this typically wouldn’t affect position, it’s worth checking.

    7. Camera Constraints: If you have any constraints or additional logic affecting camera movement, such as limits on position or rotation, make sure they are not causing the camera to behave unexpectedly.

    If you’ve checked everything and it still doesn’t work, please share your complete CameraFollow script and any relevant parts of your PlayerController script so we can take a closer look.

    #17931
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    @yentlblanckaert can you share your full CameraFollow script? You probably have some part in your script where the follow position is incorrectly set.

Viewing 2 posts - 21 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: