質問編集履歴

2

スペルの編集

2020/12/12 14:41

投稿

CraftTable
CraftTable

スコア234

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  現在FPSを開発している者です
2
2
 
3
- よくあるFPSの挙動としてスライディングの実装(TaitanfallやAPEXのような)をしようと思っています
3
+ よくあるFPSの挙動としてスライディングの実装(TitanfallやAPEXのような)をしようと思っています
4
4
 
5
5
  頭の中にあるスライディングの方法はこうです:
6
6
 

1

コードの修正

2020/12/12 14:41

投稿

CraftTable
CraftTable

スコア234

test CHANGED
File without changes
test CHANGED
@@ -26,118 +26,154 @@
26
26
 
27
27
  ```
28
28
 
29
- if (Input.GetKeyDown(KeyCode.C) && Crouching == false)
29
+ float speed;
30
30
 
31
- {
31
+ [SerializeField]
32
32
 
33
- Crouching = true;
33
+ float DashSpeed;
34
34
 
35
- }
35
+ [SerializeField]
36
36
 
37
- else if (Input.GetKeyDown(KeyCode.C) && Crouching == true)
37
+ float JanpSpeed;
38
38
 
39
- {
39
+ [SerializeField]
40
40
 
41
- Crouching = false;
41
+ float WalkSpeed;
42
42
 
43
+ [SerializeField]
44
+
45
+ float CrouchingSpeed;
46
+
47
+ [SerializeField]
48
+
49
+ GameObject Camera;
50
+
43
- }
51
+ Rigidbody rb;
52
+
53
+ [SerializeField]
54
+
55
+ bool Crouching;
44
56
 
45
57
 
46
58
 
47
- if (Crouching == true)
59
+ void Update
48
60
 
49
- {
61
+ {
50
62
 
51
- Camera.transform.position = new Vector3(transform.position.x, transform.position.y + 0.619f, transform.position.z);
63
+ if (Input.GetKeyDown(KeyCode.C) && Crouching == false)
52
64
 
53
- speed = CrouchingSpeed;
65
+ {
54
66
 
55
- }
67
+ Crouching = true;
56
68
 
57
- else
69
+ }
58
70
 
59
- {
71
+ else if (Input.GetKeyDown(KeyCode.C) && Crouching == true)
60
72
 
61
- Camera.transform.position = new Vector3(transform.position.x, transform.position.y + 1.238f, transform.position.z);
73
+ {
62
74
 
75
+ Crouching = false;
76
+
63
- }
77
+ }
78
+
79
+
80
+
81
+ if (Crouching == true)
82
+
83
+ {
84
+
85
+ Camera.transform.position = new Vector3(transform.position.x, transform.position.y + 0.619f, transform.position.z);
86
+
87
+ speed = CrouchingSpeed;
88
+
89
+ }
90
+
91
+ else
92
+
93
+ {
94
+
95
+ Camera.transform.position = new Vector3(transform.position.x, transform.position.y + 1.238f, transform.position.z);
96
+
97
+ }
64
98
 
65
99
 
66
100
 
67
- if (getshift)
101
+ if (getshift)
68
102
 
69
- {
103
+ {
70
104
 
71
- speed = DashSpeed;
105
+ speed = DashSpeed;
72
106
 
73
- }
107
+ }
74
108
 
75
- else if (Crouching == false)
109
+ else if (Crouching == false)
76
110
 
77
- {
111
+ {
78
112
 
79
- speed = WalkSpeed;
113
+ speed = WalkSpeed;
80
114
 
81
- }
115
+ }
82
116
 
83
117
 
84
118
 
85
- if (Input.GetKey(KeyCode.W))
119
+ if (Input.GetKey(KeyCode.W))
86
120
 
87
- {
121
+ {
88
122
 
89
- var tmp = -transform.forward * speed - rb.velocity;
123
+ var tmp = -transform.forward * speed - rb.velocity;
90
124
 
91
- tmp.y = 0;
125
+ tmp.y = 0;
92
126
 
93
- rb.AddForce(tmp);
127
+ rb.AddForce(tmp);
94
128
 
95
- }
129
+ }
96
130
 
97
- if (Input.GetKey(KeyCode.A))
131
+ if (Input.GetKey(KeyCode.A))
98
132
 
99
- {
133
+ {
100
134
 
101
- var tmp = -transform.right * speed - rb.velocity;
135
+ var tmp = -transform.right * speed - rb.velocity;
102
136
 
103
- tmp.y = 0;
137
+ tmp.y = 0;
104
138
 
105
- rb.AddForce(tmp);
139
+ rb.AddForce(tmp);
106
140
 
107
- }
141
+ }
108
142
 
109
- if (Input.GetKey(KeyCode.D))
143
+ if (Input.GetKey(KeyCode.D))
110
144
 
111
- {
145
+ {
112
146
 
113
- var tmp = transform.right * speed - rb.velocity;
147
+ var tmp = transform.right * speed - rb.velocity;
114
148
 
115
- tmp.y = 0;
149
+ tmp.y = 0;
116
150
 
117
- rb.AddForce(tmp);
151
+ rb.AddForce(tmp);
118
152
 
119
- }
153
+ }
120
154
 
121
- if (Input.GetKey(KeyCode.S))
155
+ if (Input.GetKey(KeyCode.S))
122
156
 
123
- {
157
+ {
124
158
 
125
- var tmp = transform.forward * speed - rb.velocity;
159
+ var tmp = transform.forward * speed - rb.velocity;
126
160
 
127
- tmp.y = 0;
161
+ tmp.y = 0;
128
162
 
129
- rb.AddForce(tmp);
163
+ rb.AddForce(tmp);
130
164
 
131
- }
165
+ }
132
166
 
167
+
133
168
 
169
+ if (Input.GetKeyDown(KeyCode.Space))
134
170
 
135
- if (Input.GetKeyDown(KeyCode.Space))
171
+ {
136
172
 
137
- {
173
+ rb.velocity = new Vector3(rb.velocity.x, JanpSpeed, rb.velocity.z);
138
174
 
139
- rb.velocity = new Vector3(rb.velocity.x, JanpSpeed, rb.velocity.z);
175
+ }
140
176
 
141
- }
177
+ }
142
178
 
143
179
  ```