Unity3D脚本 模拟Agar.io 游戏 其中细胞的分裂与融合
在模仿Agar.io游戏在分裂与融合这里卡住了;
两个物体碰撞后怎么判定晓得物体消失,大的物体体积变大?
点击键盘space按键后,细胞分裂成两个小的细胞,其中一个会施加一个速度向着鼠标方向快速移动;
游戏网址:http://agar.io
void OnCollisionEnter(Collision collision) //融合分裂体
{
if (collision.transform.tag == "Player") {
OtCellradio = collision.gameObject.transform.localScale.x;
if (true) {
if (gameObject.transform.localScale.x > OtCellradio) {
print ("大");
CellRadio = 2 * Mathf.Sqrt (((gameObject.transform.localScale.x * gameObject.transform.localScale.x) + OtCellradio * OtCellradio) / 4);
CellRadio = (CellRadio - gameObject.transform.localScale.x) / 3 + gameObject.transform.localScale.x;
gameObject.transform.localScale = new Vector3 (CellRadio, CellRadio, CellRadio);
//CloneCell.tunshi=false;
//Invoke("Opentunshi",1);
} else {
print ("小");
Maincontrl.Cellpos.Remove(gameObject); //从链表中移除该物体;
Destroy (gameObject);
}
}
}
}
void Split() //分裂
{
if (gameObject.transform.localScale.x > 1.41f) { //是否达到分裂数值?
if (Input.GetKeyDown (KeyCode.Space)) {
//CloneCell.tunshi=false;
//Invoke("Opentunshi",1);
obj = Instantiate (gameObject, gameObject.transform.position, gameObject.transform.rotation)as GameObject;
obj.transform.localScale = gameObject.transform.localScale / Mathf.Sqrt (2);
gameObject.transform.localScale = gameObject.transform.localScale / Mathf.Sqrt (1.9f);
//gameObject.GetComponent<Rigidbody>().AddExplosionForce(2000,newVector3(obj.transform.localPosition.x,obj.transform.localPosition.y,obj.transform.localPosition.z-1),3);
obj.GetComponent<Rigidbody> ().AddForce (gameObject.transform.forward * 20000 * Time.deltaTime * gameObject.transform.localScale.x);
}
}
}
这是我自己的简单想法,都是问题 请大神们来指导
{:5_387:}{:5_387:}大神请速来指导a 虽然不太懂但 鼠标控制的主物体可以当一个mainplayer来处理
这游戏挺好玩的啊 还没玩几次就掉线了 楼主是超人 好帖就是要顶 顶顶多好 LZ真是人才 难得一见的好帖 顶顶多好