Hi there
So I’ve been playing around with the drag and drop script.
and I all most got it to do what I want.
so what it does right now is. it castes a ray no the object I select with the mouse, identifies where my Player is and throws the object that way.
What I want it to do is, Destroy when it hits the player (the selected object) how do I identify that object??
var spring = 50.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.2;
var attachToCenterOfMass = false;
private var springJoint : SpringJoint;
function Update ()
{
// Make sure the user pressed the mouse down
if (!Input.GetMouseButtonDown (0))
return;
var mainCamera = FindCamera();
// We need to actually hit an object
var hit : RaycastHit;
if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit, 100))
return;
// We need to hit a rigidbody that is not kinematic
if (!hit.rigidbody || hit.rigidbody.isKinematic)
return;
//What????
if (!springJoint)
{
var go = new GameObject("Rigidbody dragger");
body = go.AddComponent ("Rigidbody");
springJoint = go.AddComponent ("SpringJoint");
body.isKinematic = true;
}
springJoint.transform.position = hit.point;
//What??
if (attachToCenterOfMass)
{
var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
anchor = springJoint.transform.InverseTransformPoint(anchor);
springJoint.anchor = anchor;
}
else
{
var Player = GameObject.Find("player");
var playerpos = Player.transform.position;
springJoint.anchor = Vector3.zero;
springJoint.transform.position = playerpos;
}
springJoint.spring = spring;
springJoint.damper = damper;
springJoint.maxDistance = distance;
springJoint.connectedBody = hit.rigidbody;
}
function FindCamera ()
{
if (camera)
return camera;
else
return Camera.main;
}
Hope you can help me
Bo