using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
    SimplePlayerを基点にenemyがバネの動きをします
    enemyにSpringコンポーネントを追加して下さい
    enemyのRigidbodyのdragには値をセットして下さい
    （0ではうまく動きません)
*/
public class Spring : MonoBehaviour {
    Rigidbody rb_;
    public GameObject target_;
    
    void Start(){
	rb_ = GetComponent<Rigidbody>();
    }

    void Update () {
	AddSpringForce(target_.transform.position, 4f);
    }

    void AddSpringForce(Vector3 target_position, float r){
	var diff = target_position - transform.position;
	var force = diff * r;
	rb_.AddForce(force);
	
    }
}
