【发布时间】:2019-12-12 11:30:51
【问题描述】:
我正在编写一个动画球多人手机游戏。球的动画非常快(速度在 25-30 左右)并且有多个球。
最初,我尝试在主客户端上运行物理并通过网络在客户端中同步。但是客户端的小球动画不是很流畅,会降低玩家的乐趣。
其次,我尝试使用以下函数在每个客户端上分别运行每个物理,但是,android 和统一编辑器之间的物理模拟是不同的。
最后,我该怎么办?
Rigidbody rb;
float t1 = 0.0f;
float t2 = 0.0f;
float scale = 2f;
float maxVelocity = 20f;
bool collided = false;
float limitSpeed = 30f;
float cooldown = 1;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void InitialKick()
{
switch (GameObject.Find("GameManager").GetComponent<GameManager>().ballCount)
{
case 1:
rb.AddForce(new Vector3(20, 0f, 20), ForceMode.Force);
break;
case 2:
rb.AddForce(new Vector3(-20, 0f, 20), ForceMode.Force);
break;
case 3:
rb.AddForce(new Vector3(20, 0f, -20), ForceMode.Force);
break;
case 4:
rb.AddForce(new Vector3(-20, 0f, -20), ForceMode.Force);
break;
case 5:
rb.AddForce(new Vector3(10, 0f, 30), ForceMode.Force);
break;
case 6:
rb.AddForce(new Vector3(-10, 0f, 30), ForceMode.Force);
break;
case 7:
rb.AddForce(new Vector3(10, 0f, -30), ForceMode.Force);
break;
case 8:
rb.AddForce(new Vector3(-10, 0f, -30), ForceMode.Force);
break;
case 9:
rb.AddForce(new Vector3(30, 0f, 10), ForceMode.Force);
break;
case 10:
rb.AddForce(new Vector3(-30, 0f, 10), ForceMode.Force);
break;
}
}
private void FixedUpdate()
{
if (!collided) InitialKick();
if (collided & rb.velocity.magnitude < maxVelocity) rb.AddForce(3f * scale * rb.velocity.normalized, ForceMode.Force);
t1 += Time.deltaTime;
if (t1 > 1.0f)
{
scale += 0.5f;
t1 = 0.0f;
}
t2 += Time.deltaTime;
if (t2 > 10.0f)
{
if (maxVelocity < 40f) maxVelocity++;
t2 = 0.0f;
}
rb.mass += Time.deltaTime * 0.01f;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "Wall" || collision.collider.tag == "Column")
{
collided = true;
}
}
}
【问题讨论】: