public void MoveByCurve(float duration, AnimationCurve xCurve, AnimationCurve yCurve, AnimationCurve zCurve)
 {
     movementCurve = new MovementCurve(duration, xCurve, yCurve, zCurve);
     SetMovementMode(MovementMode.Curve);
 }
        private void Move()
        {
            if (movementMode == MovementMode.Anchor)
            {
                if (psm.anchor != null)
                {
                    transform.position = psm.anchor.position;
                }
                else
                {
                    Debug.LogError("No anchor object");
                }
            }
            else if (movementMode == MovementMode.Player)
            {
                Vector3 desiredMove = Vector3.zero;

                if (!psm.isRooted && !psm.isStunned && pc.desiredMove.magnitude > .01f) // TODO : remove last condition if we know if really moving
                {
                    desiredMove = new Vector3(pc.desiredMove.x, 0, pc.desiredMove.y);

                    animator.SetFloat("zVel", Vector3.Dot(desiredMove, characterContainer.forward));
                    animator.SetFloat("xVel", Vector3.Dot(desiredMove, characterContainer.right));

                    bool reallyMoving = ((previousPosition - transform.position).magnitude / Time.deltaTime > moveSpeed / 6f);

                    animator.SetBool("isMoving", reallyMoving);

                    // get a normal for the surface that is being touched to move along it
                    RaycastHit hitInfo;
                    LayerMask  mask = LayerMask.GetMask("Environment");

                    Physics.SphereCast(transform.position, charController.radius, Vector3.down, out hitInfo,
                                       charController.height / 2f, mask, QueryTriggerInteraction.Ignore);
                    desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
                }
                else
                {
                    animator.SetBool("isMoving", false);
                }

                // Store position before moving
                previousPosition = transform.position;

                // add moveSpeed
                movementDirection.x = desiredMove.x * MoveSpeed();
                movementDirection.z = desiredMove.z * MoveSpeed();

                if (charController.isGrounded)
                {
                    movementDirection.y = -stickToGroundForce;
                }
                else
                {
                    movementDirection += Physics.gravity * Time.deltaTime;
                }
                charController.Move(movementDirection * Time.deltaTime);
            }
            else if (movementMode == MovementMode.Curve)
            {
                transform.position = movementCurve.GetPosition();

                if (movementCurve.isEnded())
                {
                    movementCurve = null;
                    SetMovementMode(MovementMode.Player);
                }
            }
        }