- Home /
Sphere Overlap EachOther
I have dynamically generated sphere at specific position. And when i shoot new sphere , i am assigning nearest empty position to collision contacts to that new sphere.
You can see in my previous question.
So all these works for my first row. And again when i shoot it overlapes that shooted sphere. I want to stop that sphere on collision.
code that i have written in OnCollisionEnter :
function OnCollisionEnter(collision : Collision )
{
if(transform.parent == null) // for bullet sphere , parent is null .. So collision work only for bullet
{
var contact : ContactPoint = collision.contacts[0];
var pos : Vector3 = contact.point;
var t : Transform = ClosestTransform(pos);
transform.position = t.position;
transform.rigidbody.velocity = Vector3.zero;
transform.rigidbody.angularVelocity = Vector3.zero;
transform.rigidbody.constraints = RigidbodyConstraints.FreezeAll;
if(bubbleId.Equals("Blue"))
{
t.gameObject.tag = "spawnpointBlue"; //changing tag
scriptRandomSphereObj.blueSpawnPoint = GameObject.FindGameObjectsWithTag("spawnpointBlue");
l = scriptRandomSphereObj.blueSpawnPoint.length;
Debug.Log("length :" + l); // checking length.
transform.parent = t.transform; // assign parent
}
else if(bubbleId.Equals("Red"))
{
t.tag = "spawnpointRed";
l = scriptRandomSphereObj.redSpawnPoint.length;
Debug.Log("length :" + l);
transform.parent = t.transform;
}
else if(bubbleId.Equals("Green"))
{
t.tag = "spawnpointGreen";
l = scriptRandomSphereObj.greenSpawnPoint.length;
Debug.Log("length :" + l);
transform.parent = t.transform;
}
else if(bubbleId.Equals("Yellow"))
{
t.tag = "spawnpointYellow";
l = scriptRandomSphereObj.yellowSpawnPoint.length;
Debug.Log("length :" + l);
transform.parent = t.transform;
}
else if(bubbleId.Equals("Purple"))
{
t.tag = "spawnpointPurple";
l = scriptRandomSphereObj.purpleSpawnPoint.length;
Debug.Log("length :" + l);
transform.parent = t.transform;
}
}
}
In update function :
if(Input.GetMouseButtonDown(0))
{
emptyObject = GameObject.FindGameObjectsWithTag("Empty");
for(var i : int = 0 ; i < emptyObject.Length ; i++)
{
emptyList.Add(emptyObject[i].transform);
}
Debug.Log("length " + emptyObject.Length);
}
From these arraylist , i am taking nearest empty position.
So why my sphere not detecting collision ?? Pleaze solve my issue.
I'm confused about your issue. Are you talking about a small overlap or does it just not detect the collisons? Consider setting the is$$anonymous$$inematic to true to stop your bubbles.
I have checked by setting iskinematic to true.. but same thing happens..
I don't know the Physics engine as well as I know other parts of Unity. Try setting collision detection mode in the Rigidbodies to "Continuous" or "Continuous Dynamic". Go to to Edit/Project Settings/Physics and set sleep velocity to 0.0. You are moving your "ball" through AddForce()?
yes sir.
function Update ()
{
if(transform.parent == null)
{
var hit : RaycastHit ;
var ray : Ray = Camera .main .ScreenPointToRay (Input .mousePosition );
if(Physics.Raycast (ray, hit)){
var tempx = hit.transform.position.x;
var tempy = hit.transform.position.y;
target = Vector3(tempx,tempy,0);
}
if(target != null){
var moveAmount : float = 5000 * Time.deltaTime;
transform.rigidbody.AddForce(transform.TransformDirection(target) * moveAmount);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613094703im_/https://answers.unity.com/themes/thub/images/avi.jpg)