こんにちは、Unity初心者です!スマホでタッチして水平垂直に回転させるスクリプトを作りましたが、その回転がタッチをやめるとピタッと止まってしまいます。触った後、指を離した後も、少し回転を続けて減速してから止まる。という演出を加えたいのですが、どのようにしたら良いでしょうか?よろしくお願い致します。
using
1using UnityEngine.UI; 2using System.Collections; 3using System; 4 5public class Viewer : MonoBehaviour 6{ 7 8 public float maxAngle = 60.0F; //垂直方向に回転できる上限角度 9 public float minAngle = 300.0F; //垂直方向に回転できる下限角度 10 public float rotateSpeed = 0.01f; 11 public float rotateSpeed2 = 5.0f; //回転速度(角度/秒) 12 13 public float moveSpeed = 0.05f; //スワイプ時移動速度 14 public float pinchSpeed = 0.05f; //ピンチ時移動速度 15 16 private new GameObject camera; //メインカメラ 17 private Vector2[] beforePoint; //1フレーム前のポイント(各指) 18 private Vector2[] nowPoint; //現フレームのポイント(各指) 19 private Vector2[] diffPoint; //両フレームポイント差分 20 private Vector2 difference; //二本指操作チェック用差分 21 private float horizontalAngle; 22 private float varticalAngle; 23 private float ZAngle; 24 private float horizontalPosition; 25 private float varticalPosition; 26 27 public Text texframe; 28 29 30 public GameObject target; 31 Rigidbody rb; 32 33 34 private Quaternion velocity; 35 [Range(0.0f, 1.0f)] public float Attenuation = 0.5f; 36 37 38 39 private enum State 40 { //二本指操作の状態管理用列挙型 41 DEFAULT, 42 SWIPE, 43 PINCH, 44 Roll 45 } 46 private State nowState = State.DEFAULT; //二本指操作の現在の状態 47 48 void Start() 49 { 50 camera = this.transform.Find("Main Camera").gameObject; 51 beforePoint = new Vector2[2]; 52 nowPoint = new Vector2[2]; 53 diffPoint = new Vector2[2]; 54 55 rb = GetComponent<Rigidbody>(); 56 } 57 58 59 60 61 62 void Update() 63 { 64 //1本指でタップした場合は回転 65 if (Input.touchCount == 1) 66 { 67 //押下時のポイントを取得 68 if (Input.touchCount > 0) 69 { 70 if (Input.GetTouch(0).phase == TouchPhase.Began) 71 { 72 beforePoint[0] = Input.GetTouch(0).position; 73 } 74 75 } 76 //スワイプでの継続した入力があった場合、その方向へ回転させる 77 if (Input.GetTouch(0).phase == TouchPhase.Moved) 78 { 79 nowPoint[0] = Input.GetTouch(0).position; 80 81 82 83 //水平方向の移動があった場合、水平方向に回転 84 if (nowPoint[0].x - beforePoint[0].x != 0) 85 { 86 horizontalAngle = nowPoint[0].x - beforePoint[0].x; 87 88 horizontalAngle *= rotateSpeed * Time.deltaTime; 89 90 91 //水平方向に回転させる(水平方向はワールド軸) 92 this.transform.Rotate(0, horizontalAngle, 0, Space.World); 93 94 95 96 97 float directionX = horizontalAngle; 98 99 100 } 101 102 103 //垂直方向の回転があった場合、垂直方向に回転 104 if (nowPoint[0].y - beforePoint[0].y != 0) 105 { 106 varticalAngle = - nowPoint[0].y + beforePoint[0].y; 107 varticalAngle *= rotateSpeed * Time.deltaTime; 108 109 110 111 112 //現在の角度を丸め込み(小数点第一位) 113 float tmpAngles = Mathf.Round(this.transform.rotation.eulerAngles.x * 10); 114 tmpAngles /= 10; 115 116 //垂直方向に回転させる(垂直方向はローカル軸) 117 this.transform.Rotate(varticalAngle, 0, 0, Space.Self); 118 119 120 121 122 123 float directionY = nowPoint[0].y - beforePoint[0].y; 124 125 126 127 } 128 129 //現フレームのポイントを格納 130 beforePoint[0] = nowPoint[0]; 131 } 132 } 133 134} 135コード

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/23 06:58