﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JointController : MonoBehaviour
{
    public int springStrength;
    public float damper;
    public float minDistance;
    public float maxDistance;
    public Snake snake;

    public int piecesMass;

    public int springStrengthFactor = 10;
    public int springStrengthStart = 100;

    public bool debugUpdate = false;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

        if (debugUpdate)
        {
            UpdateSettings();
            debugUpdate = false;
        }
    }

    public int snakeSpringMinimum = 10;

    public void UpdateSettings()
    {
        float springStep = ((float)springStrength - (float)snakeSpringMinimum) / (float)snake.snakeLength;

        for (int i = 0; i < snake.snakeLength; i++)
        {
            snake.snakeParts[i].GetComponent<SpringJoint>().spring = springStrength - (springStep * i);

            // snake.snakeParts[i].GetComponent<SpringJoint>().spring = springStrength;

            snake.snakeParts[i].GetComponent<SpringJoint>().damper = damper;
            snake.snakeParts[i].GetComponent<SpringJoint>().minDistance = minDistance;
            snake.snakeParts[i].GetComponent<SpringJoint>().minDistance = maxDistance;

            // snake.snakeParts[i].GetComponent<Rigidbody>().mass = piecesMass;
        }
    }

    public void UpdateStringStrength()
    {
        springStrength = springStrengthStart + (snake.snakeLength * springStrengthFactor);
    }
}
