using System.Collections; using System.Collections.Generic; using UnityEngine; //機能拡張::BBLive専用の標準関数 public static class BBLib { /* //Vector3拡張::ボールを投げる際の方向と高さを計算する public static Vector3 BallThrowAngleVec(this Vector3 self, Vector3 startPos, Vector3 targetPos) { return targetPos - startPos; } */ //Vector3拡張::ボールを投げる際の方向と高さを計算する //重力とオブジェクトの重量を考慮した計算 //引数::始点、終点、投げる対象のオブジェクトのRigidbody public static Vector3 BallThrowAngleVec(this Vector3 self, Vector3 startPos, Vector3 targetPos, Rigidbody throwObjRig) { //ゴールまでの方向をベクトルで計算する Vector3 vec_ThrowAngle = targetPos - startPos; float gravity = Physics.gravity.y;//重力加速度 //Rigidbodyの質量の変化で投げる距離が変動しないように、質量を掛けることで補正を掛ける vec_ThrowAngle *= throwObjRig.mass; gravity *= throwObjRig.mass; //3ポイントの距離を想定した高さへ調節 vec_ThrowAngle /= 2; gravity *= 1f; vec_ThrowAngle.y += -gravity; return vec_ThrowAngle; } //Vector3拡張::ボールを投げる際の方向と高さを計算する //重力とオブジェクトの重量を考慮し、投げる高さも調節できるようにする public static Vector3 BallThrowAngleVec(this Vector3 self, Vector3 startPos, Vector3 targetPos, Rigidbody throwObjRig, float throwHeight) { //ゴールまでの方向をベクトルで計算する Vector3 vec_ThrowAngle = targetPos - startPos; float gravity = Physics.gravity.y;//重力加速度 //Rigidbodyの質量の変化で投げる距離が変動しないように、質量を掛けることで補正を掛ける vec_ThrowAngle *= throwObjRig.mass; gravity *= throwObjRig.mass; float divide = 2f + throwHeight; //3ポイントの距離を想定した高さへ調節 vec_ThrowAngle /= divide; gravity *= (divide / 2f); vec_ThrowAngle.y += -gravity; return vec_ThrowAngle; } }