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 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #17914
    insects studios
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    its just moving its position on its own when i press play

    #17916
    Ser Apustaja
    Level 6
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    If the camera is moving on its own when you press play, it could be due to several reasons. Here are a few things you can check:

    1. Camera Follow Logic: Ensure that your camera follow logic is correctly implemented and not causing the camera to jump unexpectedly. If you’re using Lerp or SmoothDamp, make sure the target position is being calculated correctly.

    2. Multiple Camera Scripts: Check if there are multiple scripts attached to the camera that might be affecting its position. Disable or remove any other scripts that could be influencing the camera’s movement.

    3. Parenting Issues: Ensure that the camera is not a child of another object that is moving. If it is, it will inherit the movement of that parent object.

    4. Player Position: Check if the player’s position is being altered in a way that causes the camera to react. For example, if the player starts at an unexpected position or is moving rapidly, the camera might follow it in a way that seems erratic.

    5. Update Method: Check if you are using FixedUpdate() instead of Update() for your camera follow logic. The camera should ideally follow in Update() to ensure smooth movement.

    Here’s an example of a simple CameraFollow script:

    public class CameraFollow : MonoBehaviour
    {
        public Transform player; // Assign the player transform in the Inspector
        public Vector3 offset; // Assign offset in the Inspector
        public float followSpeed = 0.1f;
    
        void LateUpdate()
        {
            Vector3 targetPosition = player.position + offset;
            transform.position = Vector3.Lerp(transform.position, targetPosition, followSpeed);
        }
    }

    Make sure to assign the player variable in the Inspector.

    Does any of this help clarify the issue? If the problem persists, please share your CameraFollow script for further assistance.

    #17917
    insects studios
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    i used the last one but now the camera is not following the player. what do i need to type in player controller script?

    #17918
    Ser Apustaja
    Level 6
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    In your PlayerController script, you need to ensure that the PlayerController instance is properly set up as a singleton so that the CameraFollow script can access it. Here’s a reminder of how to implement the singleton pattern in your PlayerController:

    public class PlayerController : MonoBehaviour
    {
        public static PlayerController Instance;
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
        }
    
        // Other player movement code...
    }

    Make sure this code is included in your PlayerController script. This will allow the CameraFollow script to reference the player correctly.

    Additionally, ensure that you have assigned the player variable in the CameraFollow script to reference the PlayerController instance. You can do this in the Unity Inspector by dragging the player GameObject into the player field of the CameraFollow component.

    Is your PlayerController script set up correctly with the singleton pattern, and have you assigned the player reference in the CameraFollow script?

    #17919
    insects studios
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    did evrything its still moving away from the player

    #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 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: