Hi folks!
I need you opinion about this
I need to create a new object from the collision of two identical objects, then make the size of the new one equal to the sum of the two objects sizes.
Any suggestions?
Tnx
Hi folks!
I need you opinion about this
I need to create a new object from the collision of two identical objects, then make the size of the new one equal to the sum of the two objects sizes.
Any suggestions?
Tnx
What you need to look at are:
Getting the sizes right is a matter of calculating their volumes and adding them together. If they're primitive type objects, it'll be easy enough; if not, it could get a little trickier (or just guess-timate it).
Edit: question is actually a little trickier than just destroy and instantiate. This code successfully detects collisions between two rigidbodies, destroys them, and instantiates only one larger object:
var spherePrefab : GameObject;
var willSpawn : boolean = true;
//set a flag depending on if there's already been a collision or not
function canSpawn(b: boolean){
willSpawn = b;
}
function OnCollisionEnter(other:Collision){
print("collision");
var othGO: GameObject = other.gameObject;
//check the flag first so you don't do an unnecessary lookup
if (willSpawn && (othGO.name == name || othGO.name == name + "(Clone)")){ //assuming you're looking to compare two objects with the same names
othGO.SendMessage("canSpawn", false);
var newSphere: GameObject = Instantiate (spherePrefab, other.contacts[0].point, Quaternion.identity);
newSphere.transform.localScale += Vector3(2,2,2);
}
Destroy(gameObject);
}