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

Newbie Question - Player Control and Child Objects

Discussion in 'Community Learning & Teaching' started by greburt, Feb 27, 2020.

  1. greburt

    greburt

    Joined:
    Feb 27, 2020
    Posts:
    9
    Hi all,

    I've been doing the create with code tutorials and am having some issues with starting my personal project.

    I've imported a default 'filler' player (just a sphere) and created a PlayerMovement script as follows:

    public class PlayerMovement : MonoBehaviour
    {
    public float speedMultiplier;
    float horizontalInput;
    float verticalInput;

    // Start is called before the first frame update
    void Start()
    {
    speedMultiplier = 10.0f;
    }

    // Update is called once per frame
    void Update()
    {
    horizontalInput = Input.GetAxis("Horizontal");
    verticalInput = Input.GetAxis("Vertical");

    transform.Translate(Vector3.right * Time.deltaTime * speedMultiplier * horizontalInput);
    transform.Translate(Vector3.forward * Time.deltaTime * speedMultiplier * verticalInput);
    }
    }
    This works fine.

    I then duplicated the player 3 times, and made the duplicated spheres children of the main player sphere (I basically want the player's controls to move several game objects in a group simultaneously). The same PlayerMovement script applies to the duplicate spheres, and all settings between the spheres are identical in the inspector. But when I play the game, the child spheres move faster than the parent.

    If I make one of the duplicate spheres the parent, it becomes slower than the other three.

    I've tried adding a physics material to remove friction, this does nothing. Playing with the speed multiplier obviously affects them all equally, so the speed difference remains.

    Apologies if this is something really easy or obvious, any advice would be appreciated!
     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Quote:
    if you are moving the parent AND the child both having a speed for themselves, the real speed of the child object is parent's speed + child's speed, IF you want both of them to move at the same speed, just move the parent object, since the child with move along – Alfonso Nava Mar 3 '14 at 15:44
    Unquote

    Source: Unity - Child moves faster than parent - Stack Overflowstackoverflow.com › questions › unity-child-moves-faster-than-parent
     
  3. greburt

    greburt

    Joined:
    Feb 27, 2020
    Posts:
    9
    Thank you for your reply :)