포물선 공식
공을 튀기는 그림을 물리 엔진을 사용하지 않고 그려보려고 했으나 아래 방식으로 하니 비용이 그거나 그거나다 -_-;
포탄같은 경우 일정 시간 후 명중 여부를 미리 알아보는데는 유용하겠으나 프레임마다 그려주는 방식으로는 적합하지 않았다...
참고 사이트 : http://blog.naver.com/PostView.nhn?blogId=gotripgo&logNo=140088163468
StartCoroutine(Bounce(accel, angle));
IEnumerator Bounce (float accel, float angle) {
float beginTime = Time.realtimeSinceStartup;
Vector3 beginPos = gameObject.transform.localPosition;
do {
float gapTime = Time.realtimeSinceStartup - beginTime;
Vector3 newPos = Vector3.zero;
newPos.x = beginPos.x + (accel * Mathf.Cos((angle * Mathf.PI) / 180) * gapTime);
newPos.y = beginPos.y + ((accel * Mathf.Sin((angle * Mathf.PI) / 180) * gapTime) - ((GRAVITY * Mathf.Pow(gapTime, 2) / 2)));
if (newPos.y < groundPosY) {
newPos.y = groundPosY;
accel = accel * 0.7f;
beginTime = Time.realtimeSinceStartup;
beginPos = gameObject.transform.localPosition;
if (newPos.x <= leftWallPosX) {
angle -= 90;
} else if (newPos.x >= rightWallPosX) {
angle += 90;
}
if (accel < 5) accel = 0;
}
if (newPos.x <= leftWallPosX) {
newPos.x = leftWallPosX + Mathf.Abs(leftWallPosX - newPos.x);
} else if (newPos.x >= rightWallPosX) {
newPos.x = rightWallPosX - Mathf.Abs(newPos.x - rightWallPosX);
}
gameObject.transform.localPosition = newPos;
yield return null;
} while (accel != 0);