【发布时间】:2014-04-22 19:58:50
【问题描述】:
public class AsteroidMovement : MonoBehaviour
{
public Vector2 speed;
public Vector2 direction;
private Vector2 movement;
private Vector3 TopScreenBound;
private Vector3 BottomScreenBound;
// Use this for initialization
void Start()
{
TopScreenBound = Camera.main.ViewportToWorldPoint(new Vector3(0f, 1f, 0f));
BottomScreenBound = Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, 0f));
}
// Update is called once per frame
void Update()
{
if (gameObject.transform.position.y >= TopScreenBound.y)
{
direction.y *= -1;
}
if (gameObject.transform.position.y <= BottomScreenBound.y)
{
direction.y *= -1;
}
movement = new Vector2(speed.x * direction.x, speed.y * direction.y);
}
void FixedUpdate()
{
rigidbody2D.velocity = movement;
}
}
我试图让游戏中的小行星从我的屏幕边缘弹起,我已经让它正常工作,但是在几次弹跳后,小行星/物体被“卡”在墙上并在游戏区出现故障.
我做错了吗?我看不到代码中的哪个位置在几次反弹后使小行星卡住了。在此先感谢 :)
【问题讨论】:
-
“卡”在墙上,是指撞到了魔法屏障,在墙边快速来回弹跳?
标签: c# unity3d collision game-physics