public void AddForceWithMove() { Vector3 forceVector; Property ep = m_property; forceVector = Vector3.Scale(ep.m_moveToVector, m_controller.m_stick[PosType.Move]); if (m_button.JudgeButton(m_property.m_jumpButton, m_property.m_jumpMode)) { if (m_property.m_jumpVector == Vector3.zero) { m_property.m_jumpVector = Vector3.up * 500; } forceVector = m_property.m_jumpVector + forceVector; } forceVector = Vector3.Scale(ep.m_forceVector, forceVector); if (m_rigid != null) { forceVector = VecComp.LimitForce(forceVector, m_rigid.velocity, ep.m_maxVelocity, ep.m_biasMaxVelocity); m_rigid.AddForce(forceVector); } else if (m_rigid2 != null) { forceVector = VecComp.LimitForce(forceVector, m_rigid2.velocity, ep.m_maxVelocity, ep.m_biasMaxVelocity); m_rigid2.AddForce(forceVector); } }
private void PositionUpdate() { if (followObject != null) { transform.position = FollowObject.transform.position + RelativeOffset; } BaseRotation = VecComp.ExtractionAxis(transform.rotation, BaseAxis); if (Camera.main != null) { CinemachineBrain cmBrain = Camera.main.GetComponent <CinemachineBrain>(); if (CmBrain != cmBrain) { CmBrain = cmBrain; } } if (CmBrain != null) { if (CmBrain.ActiveVirtualCamera != null) { string cmName = CmBrain.ActiveVirtualCamera.Name; if (cmName != CmName) { CmName = cmName; var findCamera = GameObject.Find(CmName); if (findCamera != null) { CmCamera = findCamera.GetComponent <CinemachineVirtualCamera>(); } } } } else { CmCamera = null; } if (CmCamera != null) { // コントローラのアクティブ化、基本はFollowを参照、LookAtはFollowがNullのときだけ if (SwitchControllFromCameara && (m_controller != null)) { if (CmCamera.m_Follow != null) { m_controller.Active = (CmCamera.m_Follow.gameObject == gameObject); } else { if (CmCamera.m_Follow != null) { m_controller.Active = (CmCamera.m_LookAt.gameObject == gameObject); } else { m_controller.Active = false; } } } } }
/// <summary> /// 対象ベクトルに向かっての配置 /// </summary> public void SeeFollow(Vector3 euler, Vector3 target, float timer = DEFAULT_TIMER) { if (toEuler != euler || DoUpdate) { fromEuler = VecComp.AbsCompFloor(followerObject.transform.eulerAngles); toEuler = VecComp.EulerShortest(fromEuler, euler); if (timer <= 0f) { if (AngularVelocityOfDegree != 0f) { timer = Vector3.Distance(fromEuler, toEuler) / AngularVelocityOfDegree; } else { timer = Time.deltaTime; } } countTimer = Time.deltaTime; maxTimer = timer; if (maxTimer <= 0f) { maxTimer = SetOtherMaxTimer; } } if (maxTimer > 0f) { float ratio = countTimer / maxTimer; if (ratio >= 1f) { ratio = 1f; maxTimer = 0f; } Vector3 nextEuler = Vector3.Lerp(fromEuler, toEuler, ratio); target += RelativeOffset; Transform tf = followerObject.transform; if (mode2D) { nextEuler.x = 0; nextEuler.y = 0; } tf.eulerAngles = nextEuler; Vector3 toVector = target + -tf.forward * Distance; if (DistanceToSize && followerCamera.orthographic) { followerCamera.orthographicSize = Distance; } tf.position = toVector; } DoUpdate = false; }
new void Update() { base.Update(); if (maxTimer > 0f) { countTimer += Time.deltaTime; } SubUpdate(); if (followVector != FollowObject.transform.position) { DoUpdate = true; } followVector = FollowObject.transform.position; SeeLimit(); SeeFollow(); EulerAngle = VecComp.AbsDeg(EulerAngle); }
/// <summary> /// 視点の範囲制限、0~360で正規化 /// </summary> float SeeLimit(float value, ref float min, ref float max) { if ((max == 0f) && (min == 0f)) { return(value); } if (max < 0) { max = VecComp.AbsDeg(max); } if (min < 0) { min = VecComp.AbsDeg(min); } if (min > max) { float mid = (min + max) / 2; if (max < value && value < min) { if (mid >= value) { value = max; } else { value = min; } } } else { if (max < value) { value = max; } else if (min > value) { value = min; } } return(value); }
/// <summary> /// サブモジュール、継承してなんやかんやするならここ /// </summary> protected void SubUpdate() { if (PermissionController) { // クォータニオンで角度回転 Vector3 stick_move = m_stick[PosType.Rot]; transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.AngleAxis(stick_move.x, new Vector3(0, 1, 0)) * Quaternion.AngleAxis(stick_move.y, transform.right) * transform.rotation, Time.deltaTime * Smooth * 8); // 上下90度をキープする、yとzの中間を取る transform.rotation = VecComp.RotLimit(transform.rotation, Vector3.right, MinBaseAngle, MaxBaseAngle); // Yボタンで視点リセット RotForward(m_button.JudgeButton(ViewForwardButton, resetRotButtonMode)); // カムバックボタン if (m_button.JudgeButton(RespawnButton, ButtonMode.Down)) { FollowObject.transform.position = RespawnPosition; } } }