2020/06/20에 해당하는 글 1

2D 발사체 포물선 이동

유니티 & C#|2020. 6. 20. 20:18
Vector2 position = transform.position;

Vector2 d = destination - position;
float angle = Vector2.SignedAngle(Vector2.right, d.normalized) + 11.25f;

Vector2 p1 = new Vector2(position.x, 0f);
Vector2 d1 = new Vector2(destination.x, 0f);

float r = Vector2.Distance(p1, d1);
float t = Mathf.Tan(angle * Mathf.Deg2Rad);
float h = destination.y - position.y;

float vx = Mathf.Sqrt(Physics2D.gravity.y * r * r / (2.0f * (h - r * t)));
float vy = t * vx;

Velocity = new Vector2(vx, vy);

댓글()