Problem with SmoothDamp when applied to each child of a gameObject (188462)

Hello, I’m new to unity and, with friends, we want to make a Slither.io like game.
We made a Player Controller for our snake and we have a problem with the last 2/3 spheres composing our snake wihch don’t follow the trajectory of the rest of the body, whereas the rest of the body works fine.
Our snake is made like follows : an empty GameObject composed of a head (ball in the code below) and the body parts.

public class PlayerControler : MonoBehaviour {
    private Rigidbody rb;
    public float speed;
    Transform ball;
    private Vector3 movementVelocity;
    
    void FixedUpdate () {
        
        ball = transform.GetChild(0).transform;
        if(Input.GetKey(KeyCode.Mouse0)){
            speed = 20;
        } else {
            speed = 10;
        }
        
        if(Input.GetKey(KeyCode.Q)) {
            ball.transform.Rotate(0, Time.deltaTime * (-180), 0);
        }
        if(Input.GetKey(KeyCode.D)) {
            ball.transform.Rotate(0, Time.deltaTime * 180, 0);
        }
        
        Move();
    }
    
    void Move(){
        for (int i = transform.childCount-1; i>=0; i--){
            Transform t=transform.GetChild(i);
            
            if (i == 0){
                t.position += ball.transform.forward * speed * Time.fixedDeltaTime;
            } else {
                t.position = Vector3.SmoothDamp(t.position, transform.GetChild(i-1).transform.position, ref movementVelocity, 1.9f*Time.fixedDeltaTime, Mathf.Infinity, Time.fixedDeltaTime);
            }
        }
    }
}

We think it’s related to the SmoothDamp but we can’t figure out why.
Thanks for your help.

1 Answer

1

Does someone have an idea of what is happening ?
Thanks :wink: