【发布时间】:2019-04-26 01:50:27
【问题描述】:
我正在尝试像 pang 游戏一样进行控球。我写了这段代码,但遗漏了一些东西,或者我做错了什么。
我尝试使用物理材质,但我无法控制它。 当我将反弹设置为 1 Y 位置时,每帧都会增加。所以我对此无能为力。
private void OnTriggerEnter(Collider other)
{
Debug.Log("Collied");
if(other.tag == "rightWall")
{
direction = false;
}
else if(other.tag == "leftWall")
{
direction = true;
}
if(other.tag == "groundWall") rigid.velocity = Vector3.up * 10;
if(other.tag != "topWall") BallMove();
}
void BallMove()
{
if (direction == false)
{
rigid.AddForce(Vector3.Lerp(transform.position, new Vector3(-300f, 0, 0), Time.deltaTime * ballForce));
}
else
{
rigid.AddForce(Vector3.Lerp(transform.position, new Vector3(300f, 0,0), Time.deltaTime * ballForce));
}
}
【问题讨论】: