質問編集履歴
1
挙動がおかしくなる原因であった誤ったコード群と、質問に必要のない無駄なコードを削除。回答しようのない疑問点②を削除しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,28 +7,6 @@
|
|
7
7
|
水平移動のソースにコントローラースティックの傾き加減により加速させる仕様があるため、計算式がよくわからない事になっています。
|
8
8
|
移動に使われているソースを抜粋しました。
|
9
9
|
|
10
|
-
Controller.cs(コントローラーによる入力に関わるもの)
|
11
|
-
```
|
12
|
-
public class Controller : MonoBehaviour
|
13
|
-
{
|
14
|
-
void Awake(){playerCtrl = GetComponent<PlayerController>();}
|
15
|
-
void Update()
|
16
|
-
{
|
17
|
-
// 操作可能か?
|
18
|
-
if (!playerCtrl.activeSts) { return; }
|
19
|
-
// パッド処理
|
20
|
-
float joyMvX = Input.GetAxis("Horizontal");
|
21
|
-
float joyMvY = Input.GetAxis("Vertical");
|
22
|
-
playerCtrl.Horizontal_Move(joyMvX);
|
23
|
-
playerCtrl.Vertical_Move(joyMvY);
|
24
|
-
if (joyMvY > 0)//↑キーを押した状態
|
25
|
-
{playerCtrl.Movement_Object();}
|
26
|
-
if (joyMvY < 0 & !(Input.GetButtonDown("Jump") ))//落下
|
27
|
-
{playerCtrl.Movement_Object();}
|
28
|
-
}
|
29
|
-
}
|
30
|
-
```
|
31
|
-
|
32
10
|
PlayerController.cs
|
33
11
|
```
|
34
12
|
public class PlayerController : BaseCharacterController
|
@@ -58,75 +36,9 @@
|
|
58
36
|
{ breakEnabled = true; }// 移動停止
|
59
37
|
if (dirOld != dir){ breakEnabled = true; }//その場で振り向きチェック
|
60
38
|
}
|
61
|
-
public override void Vertical_Move(float n)//垂直移動
|
62
|
-
{
|
63
|
-
if (!activeSts) {return;}
|
64
|
-
moveSpeed = (moveSpeed < 0.5f) ? (moveSpeed * (1.0f / 0.5f)) : 1.0f;
|
65
|
-
speedVy = initSpeed * moveSpeed;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
```
|
69
39
|
|
70
|
-
BaseCharacterController.cs
|
71
40
|
```
|
72
|
-
public class BaseCharacterController : MonoBehaviour {
|
73
|
-
public Vector2 velocityMin = new Vector2(-100.0f, -100.0f);
|
74
|
-
public Vector2 velocityMax = new Vector2(+100.0f, +50.0f);
|
75
|
-
public Vector2 CharacterPosition;//現在のキャラクターの座標
|
76
|
-
protected float speedVx = 0.0f;
|
77
|
-
protected float speedVxAddPower = 0.0f;
|
78
|
-
protected float speedVy = 0.0f;
|
79
|
-
protected float speedVyAddPower = 0.0f;
|
80
|
-
public Rigidbody2D RB;
|
81
|
-
[System.NonSerialized] public float dir = 1.0f;//方向の指定
|
82
|
-
[System.NonSerialized] public float speed = 1.0f;
|
83
|
-
[System.NonSerialized] public float basScaleX = 1.0f;
|
84
|
-
[System.NonSerialized] public bool groundedPrev = false;
|
85
41
|
|
86
|
-
protected virtual void FixedUpdate() {
|
87
|
-
|
88
|
-
//方向チェック
|
89
|
-
if (transform.localScale.x > 0.0f) { facing = true; }
|
90
|
-
else if (transform.localScale.x < 0.0f) { facing = false; }
|
91
|
-
|
92
|
-
// 移動計算
|
93
|
-
RB.velocity = new Vector2(speedVx, RB.velocity.y);
|
94
|
-
|
95
|
-
// Veclocityの値をチェック
|
96
|
-
float vx = Mathf.Clamp(RB.velocity.x, velocityMin.x, velocityMax.x);
|
97
|
-
float vy = Mathf.Clamp (RB.velocity.y, velocityMin.y, velocityMax.y);
|
98
|
-
RB.velocity = new Vector2(vx,vy);
|
99
|
-
|
100
|
-
//キャラクターの現在座標の記録
|
101
|
-
beforeCharacterPosition = CharacterPosition;
|
102
|
-
|
103
|
-
public virtual void Horizontal_Move(float n) {
|
104
|
-
if (grounded ==true && air == false)//滞空時に歩行アニメーションを表示させない
|
105
|
-
{
|
106
|
-
if (n != 0.0f)//左右に移動している
|
107
|
-
{
|
108
|
-
dir = Mathf.Sign(n);//移動している方向を-+でdirに出力
|
109
|
-
speedVx = speed * n;
|
110
|
-
animator.SetTrigger("Run");
|
111
|
-
}
|
112
|
-
else
|
113
|
-
{
|
114
|
-
speedVx = 0;
|
115
|
-
animator.SetTrigger("Idle");
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
public virtual void Vertical_Move(float n)
|
120
|
-
{
|
121
|
-
if (n != 0.0f)
|
122
|
-
{
|
123
|
-
dir = Mathf.Sign(n);
|
124
|
-
speedVy = speed * n;
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
```
|
130
42
|
### 疑問点
|
131
43
|
①
|
132
44
|
```
|
@@ -136,26 +48,4 @@
|
|
136
48
|
0.5f以上場合は1.0fにして、0.5f以下の場合にmoveSpeedを2倍すると移動としておかしなものになる様な気がします。
|
137
49
|
この計算式(moveSpeed * (1.0f / 0.5f))部分は何を行っているものでしょうか?
|
138
50
|
|
139
|
-
②
|
140
|
-
```
|
141
|
-
public override void Vertical_Move(float n)//垂直移動
|
142
|
-
{
|
143
|
-
if (!activeSts) {return;}
|
144
|
-
moveSpeed = (moveSpeed < 0.5f) ? (moveSpeed * (1.0f / 0.5f)) : 1.0f;
|
145
|
-
speedVy = initSpeed * moveSpeed;
|
146
|
-
}
|
147
|
-
```
|
148
|
-
```
|
149
|
-
public virtual void Vertical_Move(float n)
|
150
|
-
{
|
151
|
-
if (n != 0.0f)
|
152
|
-
{
|
153
|
-
dir = Mathf.Sign(n);
|
154
|
-
speedVy = speed * n;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
```
|
158
|
-
|
159
|
-
|
51
|
+
②[無意味なコードであったことが分かりましたので、質問と言えず削除しました。]
|
160
|
-
上記部分のソースで最低限の垂直移動ができるのではないかと考えたのですが、Rigitboddy2D(重力)の有無に関係なく無反応でした。
|
161
|
-
エラーメッセージも出ていません。何か改善方法はありますでしょうか?
|