Question by
oldronin · Dec 07, 2018 at 11:09 AM ·
collision2d
Trouble with earlier triggered
I have an object that falls from top to bottom and collides with a target. And when I click on an object and move it with the mouse to the target, the collision is triggered earlier. on the screen is an object in the trigger position, and the blue square shows where the object is in the view of the calider
Movement script in Object
void OnMouseDrag()
{
Vector2 currentMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector2(currentMousePosition.x, currentMousePosition.y);
}
Trigger script in Target making the blue mark:
void OnTriggerEnter2D(Collider2D col)
{
GameObject PointCandy = GameObject.Find("PointCandy");
Transform tr_PointCandy = PointCandy.transform;
Transform tr_candy = col.gameObject.transform;
tr_PointCandy.position = new Vector2(tr_candy.position.x, tr_candy.position.y);
}
Object - blue/white candy
Target - Yellow rectangle
Blue mark - blue square
for-faq-unity.jpg
(12.9 kB)
Comment
Your answer
Follow this Question
Related Questions
OnCollisionEnter2 problem. 1 Answer
How to have an object with rigidbody touch another object with isTrigger true 1 Answer
Unity2d move enemy in opposite direction on collision 1 Answer
Unity bug gives false error messages or doesen't work without a Debug.Log() line present 1 Answer
Top Down 2D Jumping 0 Answers