using UnityEngine;
using System.Collections;

public class TractorBeam : MonoBehaviour 
{
    public Rigidbody connectedBody;
    public float k = 100.0f;
    public float c = 10.0f;
    public Vector3 offset;

	// Use this for initialization
	void Start() 
    {
	
	}
	
	// Update is called once per frame
	void FixedUpdate()
    {
        Vector3 dist = transform.position - connectedBody.transform.position;
        Vector3 force = (k * dist) - (c * connectedBody.velocity);

        Vector3 transformedOffsetZ = connectedBody.transform.forward * offset.z;
        Vector3 transformedOffsetX = connectedBody.transform.right * offset.x;
        Vector3 transformedOffsetY = connectedBody.transform.up * offset.y;
        Vector3 totalOffset = transformedOffsetX + transformedOffsetY + transformedOffsetZ;
        connectedBody.AddForceAtPosition(force, connectedBody.position + totalOffset);
	}
}
