Mouse Drag and drop - object dropped not triggering or colliding

Used the code from here: http://forum.unity3d.com/threads/64169-Drag-amp-drop-game-objects-(without-rigidbody)-with-the-mouse

Trying to detect when that object is inside /over another gameObject, tried using OnTriggerEnter, and OnCollisionEnter scripts:

// Destroy everything that enters the trigger

function OnTriggerEnter (other : Collider) {
	//Destroy(other.gameObject);
	Debug.Log("hey");
}

function OnCollisionEnter (other: Collision){
	Debug.Log("Collision");
	}	

And even with trigger turned on in the inspector and rigid bodies on one and both objects - I’m not getting the collision or the trigger to fire.

IF I go into scene view and move the detection gameobject, it fires that code. Just not when I’m playing the scene and dragging the object. What am I missing?

Colliding….stupid me

Directly modifying the transform is teleporting the object, and collider can be missed. Not sure if this is your issue or not, but consider changing code like this: target.transform.position = curPosition; to: target.rigidbody.MovePosition(curPosition):

WRT 'colliging' you can edit your question and fix problems.

2 Answers

2

After I stepped away for a few moments, I noticed I had the detect script on the “activation” object and not on the object I was dragging. Once I moved it to the drag object - it was working…I’ll be interested to see if changing the script to your solution will work…I’ll let you know, because it would be nice to move that functionality to multiple regions to activate the change in behaviors for the dragging object. Thanks Robertbu!!

Hello @ThirdrowDE, I Just wanted to know if you did suceed on this one. I have the same Problem. Thanx.

The only solution I came up with is to hardcode the x and y positions (I am dragging treats and dropping them into the dog’s mouth which is located between -110.35 and -110.0 on the x axis and between -111.40 and -112.00 on the y axis): -

	if (Input.GetMouseButtonUp (0)) 
	{
		_mouseState = false;

		if (target.transform.position.x>-110.35f && target.transform.position.x< -110.0f && target.transform.position.y <-111.4f && target.transform.position.y >-112.0f)
			//you have found the dog's face [code is ugly but the face is cute]
		{
			Debug.Log ("yum yum woofation");
			Destroy(target);
		}

	}