Last active
October 23, 2019 16:18
-
-
Save IamGroooooot/84dabf22fdd648cd8355c3508e5cb9f8 to your computer and use it in GitHub Desktop.
포탄(Bomb)을 포물선으로 발사할 때의 속도(velocity)를 계산하는 유니티 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//포물선으로 쏘는것 | |
void FireSkelBomb(GameObject Bomb) | |
{ | |
playerPos = PlayerTrans.position; | |
displace = playerPos - transform.position; | |
distance = Mathf.Pow((displace.x) * (displace.x) + (displace.z) * (displace.z), 0.5f); //수평도달거리 계산 | |
BombInitVelocity = new Vector3(displace.x, distance * Mathf.Tan(angle_degr * Mathf.Deg2Rad), displace.z).normalized; //내가 포물선으로 쏠 벡터의 단위벡터 계산 | |
BombInitVelocity = BombInitVelocity * Mathf.Sqrt( Mathf.Abs(Physics.gravity.y) * distance / Mathf.Sin(2 * angle_degr * Mathf.Deg2Rad); //물리식 속도는 중력에 비례하기 때문에 *중력 수정함* | |
Bomb.GetComponent<Rigidbody>().velocity = BombInitVelocity; //폭탄 인스턴트에 속도 부여 | |
Bomb.GetComponent<TrailRenderer> ().Clear(); | |
//Bomb.gameObject.SetActive (false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment