/// <summary> /// 向目标投掷匕首 /// </summary> public void ThrowingDaggerForAim(Vector3 aim, float speed) { //设置摄像头绘制轨迹的对象 drawCurve = Camera.main.GetComponent <DrawCurve>(); drawCurve.Dagger = gameObject; //初始化匕首质量,速度 mass = Random.Range(0.4f, 2f); ThrowSpeed = speed; //计算投掷角度 if (mass * gravity * (aim.y - transform.position.y) > mass / 2 * Mathf.Pow(speed, 2)) { ThrowAngle = 90; } else { ThrowAngle = GetAngle(aim, speed); } //计算初始速度矢量 float cos = Mathf.Cos(ThrowAngle * Mathf.Deg2Rad); float sin = Mathf.Sin(ThrowAngle * Mathf.Deg2Rad); Velocity = new Vector3(ThrowSpeed * cos, ThrowSpeed * sin, 0); //利用协程更新匕首状态 StartCoroutine(UpdateCorrespondence(0.15f)); }
//随机投掷匕首 public void RandomThrowingDagger() { //设置摄像头绘制轨迹的对象 drawCurve = Camera.main.GetComponent <DrawCurve>(); drawCurve.Dagger = gameObject; //初始化投掷角度,速度,匕首质量 ThrowAngle = Random.Range(10f, 80f); ThrowSpeed = Random.Range(4f, 10f); mass = Random.Range(0.4f, 2f); //计算初始速度矢量 float cos = Mathf.Cos(ThrowAngle * Mathf.Deg2Rad); float sin = Mathf.Sin(ThrowAngle * Mathf.Deg2Rad); Velocity = new Vector3(ThrowSpeed * cos, ThrowSpeed * sin, 0); //利用协程更新匕首状态 StartCoroutine(UpdateCorrespondence(0.15f)); }