Rigidbody over trigger collider doesn't allow to interact with it

I have Launcher object which has only circle collider and a script attached to it. Circle collider is set to be a trigger and the script executes 2 main functions:

  1. Instantiates projectile at launch pad

  2. Launches projectile

Instantiation occurs at Start(). To launch projectile I want player to click at defined by collider area (slightly bigger than projectile itself), drag to desired direction and launch by releasing mouse button. It generally works as intended.

But here is my problem:
After bein instantiated in the middle of circle collider, projectile object kinda “overlaps” it and I have to hit small area between the edges of the circle collider and projectile’s collider to start launch sequence =(

Any ideas how to fix it?

Here’s the code:

using UnityEngine;
using System.Collections;

public class PlayerLauncher : MonoBehaviour
{

	public float velocityMultiplier = 1.0f;
	public float velocityClamp;

	public GameObject playerToThrow;
	public Vector2 spawnPosition;

	private GameObject playerClone;

	void Start()
	{
		playerClone = Instantiate (playerToThrow, spawnPosition, Quaternion.identity) as GameObject;
	}
	
	void OnMouseUp()
	{
		var playerPosition = playerClone.transform.position;
		var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		var velocityVector = mousePosition - playerPosition;
	
		playerClone.rigidbody2D.isKinematic = false;
		playerClone.rigidbody2D.velocity = Vector2.ClampMagnitude(new Vector2(velocityVector.x,velocityVector.y),velocityClamp)*velocityMultiplier;

	}
}

P.S. Sorry for my lame English. And if the problem is not in code itself, please suggest possible reasons…

Hi,

disable the CircleCollider2D of the playerClone after you instantiated it. Enable the CircleCollider2D of the playerClone in the first line of the OnMouseUp() method.

e.g.:

using UnityEngine;
using System.Collections;

public class PlayerLauncher : MonoBehaviour
{
	public float velocityMultiplier = 1.0f;
	public float velocityClamp;
	
	public GameObject playerToThrow;
	public Vector2 spawnPosition;
	
	private GameObject playerClone;
	private CircleCollider2D circleCollider;
	
	void Start()
	{
		playerClone = Instantiate (playerToThrow, spawnPosition, Quaternion.identity) as GameObject;
		circleCollider = (CircleCollider2D)playerClone.GetComponent(typeof(CircleCollider2D));
		circleCollider.enabled = false;
	}
	
	void OnMouseUp()
	{
		circleCollider.enabled = true;
		var playerPosition = playerClone.transform.position;
		var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		var velocityVector = mousePosition - playerPosition;
		
		playerClone.rigidbody2D.isKinematic = false;
		playerClone.rigidbody2D.velocity = Vector2.ClampMagnitude(new Vector2(velocityVector.x,velocityVector.y),velocityClamp)*velocityMultiplier;
	}
}

It should work.