카테고리 없음

포물선 궤적

일등하이 2020. 5. 27. 15:22
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using UnityEngine; 
using System.Collections; 
public class Ball : MonoBehaviour 
    public GameObject ball; // 공 
    float v = 50// 초속도 
    float th = 60// 발사각도 
    float t = 0// 시간 
    float g = 9.80665f; // 중력가속도 상수 
    float h = 0// 높이 
    float d = 0// 거리 
    
    
    // Update is called once per frame 
    void Update () { 
        if (h < 0returnfloat r = th * Mathf.Deg2Rad; // 각도를 라디안으로 변환 
        h = v * t * Mathf.Sin(r) - 0.5f * g * t * t; 
        d = v * t * Mathf.Cos(r); 
        Vector3 pos = new Vector3(d, h, 0); 
        Instantiate(ball, pos, Quaternion.identity); t += 0.1f; // 0.1초 단위로 계산 
    } 
}
cs
반응형