Skip to content

Instantly share code, notes, and snippets.

@IamGroooooot
Last active October 23, 2019 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IamGroooooot/84dabf22fdd648cd8355c3508e5cb9f8 to your computer and use it in GitHub Desktop.
Save IamGroooooot/84dabf22fdd648cd8355c3508e5cb9f8 to your computer and use it in GitHub Desktop.
포탄(Bomb)을 포물선으로 발사할 때의 속도(velocity)를 계산하는 유니티 코드
//포물선으로 쏘는것
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