Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Child not Following Parent Properly

Discussion in 'Editor & General Support' started by girlinorbit, Jun 26, 2020.

  1. girlinorbit

    girlinorbit

    Joined:
    Apr 27, 2019
    Posts:
    114
    I have a camera as a child of a player game object. It's supposed to follow the player smoothly, but instead it follows it like it was on a rubber band, falling back and then catching up.

    Here's my code:



    Code (CSharp):
    1.  
    2.             transform.position += transform.forward * speed * Gait * Time.deltaTime;
    3.             transform.Rotate(0, Input.GetAxis("Horizontal"), 0);
    4.             camera.transform.localPosition = new Vector3(0f,3f,-3.5f);
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Well, there's no reason you need to keep setting the localPosition of the camera every frame. You should be able to set that just once. You're sure there isn't any other code affecting the camera position?
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Only thing I see fishy in your code snippet is what @dgoyette said about localPosition, and that your transform.Rotate call is framerate-dependent because it doesn't take Time.deltaTime into account.
     
  4. girlinorbit

    girlinorbit

    Joined:
    Apr 27, 2019
    Posts:
    114
    @dgoyette @PraetorBlue

    Even when I remove that line, it continues to do the same thing. There is nothing else affecting the gameobject.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Maybe if you could explain your object hierarchy better? Which object ios this script attached to?
     
  6. girlinorbit

    girlinorbit

    Joined:
    Apr 27, 2019
    Posts:
    114
    Here is my object's hierarchy. The Camera is the object I'm trying to control. If I put it under the Armature it does the same thing.

    upload_2020-6-26_15-32-53.png
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Where is all this in relation to the player? Is the horse the player? What's an armature? Which object is the script above attached to?
     
  8. girlinorbit

    girlinorbit

    Joined:
    Apr 27, 2019
    Posts:
    114
    Oh and the script is on the parent gameobject.
     
  9. girlinorbit

    girlinorbit

    Joined:
    Apr 27, 2019
    Posts:
    114
    The player mounts inside the armature. The armature is the skeleton.
     
  10. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    If this is an animated object, typically you'd attach moving objects to some object within the armature, since that's the part that manifests the animated movement. I'm not sure what bone would make the most sense here, maybe the head bone, or a back bone of the horse? But maybe you can parent the camera to one of those bones and see if that improved the result?
     
  11. MavelanWasTaken

    MavelanWasTaken

    Joined:
    Nov 24, 2020
    Posts:
    1
    I have the same issue. Did you find the solution?