お世話になります。
現在タッチスクリーンをタップしたらキャラクターがそのタッチした場所に移動するスマホゲームを作っています。
以下の処理を処理を作りたいのですが、問題が起きており困っています。
作りたい処理:エリア(ステージ)端へキャラクター(以下Player1と記述)を移動しても
Player1がカクカクせずにスムーズに移動できるようにすること。
問題:エリア端にキャラクターを移動したときに
Player1がカクカク(エリア端で引っかかったような挙動)をすることです。
作成したスクリプト:
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Common; 5using System; 6 7/// <summary> 8/// Player1を操作するクラス 9/// 主に移動処理を書いている。 10/// </summary> 11public class Player1Controller : MonoBehaviour 12{ 13 // Player1のバトル開始座標 14 const float player1_startPositionX = -410.0f; 15 const float player1_startPositionY = -92.0f; 16 17 // タッチパネルをタップした位置を取得する変数 18 Touch touch; 19 Vector3 touchPosition; 20 21 // Player1を約1マス分前へ表示 22 Vector3 oneSquareForward = new Vector3(60.0f, 0.0f); 23 24 // Use this for initialization 25 void Start() 26 { 27 // このtransform自身のlocalPositionを初期化 28 this.transform.localPosition = new Vector3( 29 player1_startPositionX, 30 player1_startPositionY, 31 0.0f 32 ); 33 } 34 35 // Update is called once per frame 36 void Update() 37 { 38 if (Input.touchCount > 0) 39 { 40 // タッチパネルをタップした位置を取得 41 touch = Input.GetTouch(0); 42 43 touchPosition = Camera.main.ScreenToWorldPoint(touch.position); 44 45 touchPosition.z = 0.0f; 46 47 // Player1が青エリア内のみ移動 48 if (touchPosition.y < BattleArea.myUpperSide && 49 BattleArea.myLowerSide < touchPosition.y && 50 touchPosition.x + oneSquareForward.x < BattleArea.myRightSide && 51 BattleArea.myLeftSide < touchPosition.x + oneSquareForward.x) 52 { 53 this.transform.position = 54 touchPosition + oneSquareForward; 55 } 56 } 57 } 58} 59
それほど重い処理ではないと思いますし、なぜエリア端でカクカクした動きになってしまうかが分かりません。
どうかアドバイスをお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/14 21:35
2019/03/15 04:49
2019/03/15 11:59