/
MoveShip.cs
504 lines (368 loc) · 21 KB
/
MoveShip.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
using UnityEngine;
using System.Collections;
public class MoveShip : MonoBehaviour {
//The starting values given here are the defaults for when the scrip is first attached to an object (like if you put it on a new ship)
//They mainly serve as a reference for what sort of values should be given.
public float forwardAccel = 15, backwardAccel = 6, strafeAccel = 10, strafeAndReverseSpeedLimit = 12, forwardSpeedLimit = 20 /* backwardSpeedLimit = 3,
, strafeSpeedLimit = 7, maxSpeedMagnitude = 14*/;
//boostAccelerationMultiplier = 1.25f, maxBoostSpeedMagnitude = 20;
float speedLimitToUse;//Speed limit which is calculated based on ship's facing
public float rotationSpeed;
//public float maxBoostDuration = 3, fullBoostRechargeTime = 3, boostRechargeDelay = 0.5f;
//float remainingBoostDuration, remainingBoostRechargeDelay;
//bool boostButtonPressed;
public AudioSource thrusterSound;
//Both should probably range from about 0.5 to 1
float thrusterIdleVolume, thrusterIdlePitch;
public GameObject rightThruster, leftThruster, rightFrontThrust, leftFrontThrust;
//Virtual joystick
public VirtualJoyStick movementJoystick, directionShootingJoystick;
Vector2 velocityToCheck; //Used as a holder for velocity, so it can be checked before being applied
Vector2 velocityToAdd; //Another holder for velocity, after it has been checked, but not yet applied
float angleDifference;
float originalDrag;
public float wallHitSlow = 1;
Vector2 myVelocity;
//More holders
ParticleSystem.EmissionModule theParticleSystem;
ParticleSystem.MinMaxCurve theParticleSystemsRateCurve;
int frostStacks;
float percentageFrostSlow;
/*Vector3 curAc, zeroAc;
float GetAxisV;
float GetAxisH;*/
// Use this for initialization
void Start () {
if (PlayerPrefs.GetInt ("realisticMovementOnBool") == 1) {
forwardAccel = 27;
backwardAccel = 32;
strafeAccel = 32;
strafeAndReverseSpeedLimit = 17;
forwardSpeedLimit = 21;
gameObject.GetComponent<Rigidbody2D> ().drag = 0.2f;
} else {
forwardAccel = 50;
backwardAccel = 50;
strafeAccel = 50;
strafeAndReverseSpeedLimit = 16;
forwardSpeedLimit = 18;
gameObject.GetComponent<Rigidbody2D> ().drag = 2;
}
originalDrag = gameObject.GetComponent<Rigidbody2D> ().drag;
//If first move upgrade is unlocked
if (PlayerPrefs.GetInt("moveUpgradeLevel") >= 1)
{
forwardAccel *= 1.25f;
backwardAccel *= 1.25f;
strafeAccel *= 1.25f;
}
//If second move upgrade is unlocked
if (PlayerPrefs.GetInt("moveUpgradeLevel") >= 2)
{
forwardSpeedLimit *= 1.25f;
strafeAndReverseSpeedLimit *= 1.25f;
//strafeSpeedLimit *= 1.4f;
}
//If third move upgrade is unlocked
if (PlayerPrefs.GetInt("moveUpgradeLevel") >= 3)
{
}
//remainingBoostDuration = maxBoostDuration;
//ResetAxes ();
thrusterIdleVolume = thrusterSound.volume;
thrusterIdlePitch = thrusterSound.pitch;
}
// Update is called once per frame
void Update () {
/*//mobile input stuff
float smooth = 1, sensV = 1, sensH = 1;
CurAc = Vector3.Lerp(curAc, Input.acceleration-zeroAc, Time.deltaTime/smooth);
GetAxisV = Mathf.Clamp(curAc.y * sensV, -1, 1);
GetAxisH = Mathf.Clamp(curAc.x * sensH, -1, 1);*/
float previousAngle = transform.rotation.eulerAngles.z;
myVelocity = gameObject.GetComponent<Rigidbody2D>().velocity;//Gets our current velocity, used for sound, and speed checks
float currentSpeed = myVelocity.magnitude;
//Analog Rotating stuff
if (directionShootingJoystick.Vertical () < 0) {//Checks if the shoot analog/keys has negative vertial direction. If so, a negative rotation is applied (ask Ben if needed).
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
-Vector2.Angle (Vector2.right, new Vector2 (directionShootingJoystick.Horizontal (), directionShootingJoystick.Vertical ())) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*/ );
} else if (directionShootingJoystick.Vertical () != 0 || directionShootingJoystick.Horizontal() != 0) {//Checks if the shoot analog/keys is in use in any other direction
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
Vector2.Angle (Vector2.right, new Vector2 (directionShootingJoystick.Horizontal (), directionShootingJoystick.Vertical ())) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*/ );
} else if (movementJoystick.Vertical () < 0) {//Checks if the move analog/keys has negative vertial direction. If so, a negative rotation is applied (ask Ben if needed).
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
-Vector2.Angle (Vector2.right, new Vector2 (movementJoystick.Horizontal (), movementJoystick.Vertical ())) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60)/* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*/);
} else if (movementJoystick.Vertical () != 0 || movementJoystick.Horizontal() != 0) { //Checks if the move analog/keys is in use in any other direction
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
Vector2.Angle (Vector2.right, new Vector2 (movementJoystick.Horizontal (), movementJoystick.Vertical ())) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*/ );
}
//Should ship also start shooting?
if (directionShootingJoystick.Vertical () != 0 || directionShootingJoystick.Horizontal () != 0) {
gameObject.GetComponent<Shoot> ().startShooting ();
}
/*//This is purely a control for PC/Mac. It checks keyboard input at the same time so it only works to shoot as you move, but doesn't work on mobile touch screens
else if (Input.GetMouseButton (0) && (Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.D))) {//Mouse control for pc/mac where mouse is used to aim and shoot
gameObject.GetComponent<Shoot> ().startShooting ();
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Vector2 mouseRelativePos = new Vector2 (mouseWorldPos.x - transform.position.x, mouseWorldPos.y - transform.position.y);
if (mouseRelativePos.y > 0) {
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
Vector2.Angle (Vector2.right, new Vector2 (mouseRelativePos.x, mouseRelativePos.y)) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*//*);
} else {
transform.rotation = Quaternion.RotateTowards (
transform.rotation, Quaternion.AngleAxis (
-Vector2.Angle (Vector2.right, new Vector2 (mouseRelativePos.x, mouseRelativePos.y)) - 90f,
Vector3.forward),
rotationSpeed * (Time.deltaTime * 60) /* (1.3f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude), 0.3f, 1f))*//*);
}
}*/ else {
gameObject.GetComponent<Shoot> ().stopShooting ();//As the shoot analog wasn't in use, don't shoot
}
//Zero all the thrusters
theParticleSystem = rightThruster.GetComponent<ParticleSystem> ().emission;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
theParticleSystem = leftThruster.GetComponent<ParticleSystem> ().emission;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
//Increase particles to front thrusts
theParticleSystem = rightFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
theParticleSystem = leftFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
//All thrusters are now zeroed
float newAngle = transform.rotation.eulerAngles.z;
float rotationAmount = newAngle - previousAngle;
if (rotationAmount > 0) {
//Increase particles to rear thrusts
theParticleSystem = rightThruster.GetComponent<ParticleSystem> ().emission;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 100;
theParticleSystem.rate = theParticleSystemsRateCurve;
theParticleSystem = leftFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 100;
theParticleSystem.rate = theParticleSystemsRateCurve;
} else if (rotationAmount < 0) {
theParticleSystem = leftThruster.GetComponent<ParticleSystem> ().emission;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 100;
theParticleSystem.rate = theParticleSystemsRateCurve;
//Increase particles to front thrusts
theParticleSystem = rightFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax = 100;
theParticleSystem.rate = theParticleSystemsRateCurve;
}
//Movement and sound
Vector2 moveAngleInput = new Vector2 (movementJoystick.Horizontal (), movementJoystick.Vertical ());
//Vector2 myVelocity = gameObject.GetComponent<Rigidbody2D>().velocity;//Gets our current velocity, used for sound, and speed checks
float thrustMagnitude = moveAngleInput.magnitude;//This is just for sound
//float percentOfThrustFromRear = (180 - Mathf.Abs(Vector2.Angle (Vector2.right, new Vector2 (transform.up.x,transform.up.y)) - Vector2.Angle (Vector2.right, new Vector2 (movementJoystick.Horizontal (), movementJoystick.Vertical ())))) / 180;
thrusterSound.pitch = thrusterIdlePitch + myVelocity.magnitude / 30 + (thrustMagnitude / 3); //Increase pitch a bit more for faster sound
thrusterSound.volume = thrusterIdleVolume + myVelocity.magnitude / 100 + (thrustMagnitude / 3);
//This works good as well
//velocityToAdd += moveAngleInput * (((180 - angleDifference) / 360) + 0.5f);
//angle of analog from nose
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.up.x, transform.up.y)));
if (angleDifference < 90) {
//Increases speed limit when going forward
speedLimitToUse = Mathf.Clamp (strafeAndReverseSpeedLimit + ((forwardSpeedLimit - strafeAndReverseSpeedLimit) * (1 - angleDifference / 90)), currentSpeed, forwardSpeedLimit);
//Add velocity for forward movement, using accerlation curve
velocityToAdd += (moveAngleInput * (1 - angleDifference / 90) * forwardAccel * Time.deltaTime) * (1.5f - Mathf.Clamp ((currentSpeed / forwardSpeedLimit - 4), 0.5f, 1f));
} else {
speedLimitToUse = Mathf.Clamp (strafeAndReverseSpeedLimit, currentSpeed, forwardSpeedLimit);
}
speedLimitToUse *= (1 - percentageFrostSlow);
//Debug.Log (currentSpeed);
//Inrcase velocity in move direction accordingly
//Limit magnitude based on newly calculated top speed
/*
//Try to apply some amount forward velocity
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.up.x, transform.up.y)));
if (angleDifference < 90) {
//velocity to add is here
velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * forwardAccel * Time.deltaTime;
velocityToCheck *= 1.5f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude - 4), 0.5f, 1f);//Better working one
//float currentSpeed = myVelocity.y * -transform.up.y + myVelocity.x * -transform.up.x;
float newSpeed = (myVelocity.y + velocityToCheck.y) * transform.up.y + (myVelocity.x + velocityToCheck.x) * transform.up.x;
//Don't add it if it puts you over the speed limit
if (newSpeed < forwardSpeedLimit * (1 - angleDifference / 90)) {
velocityToAdd += velocityToCheck;
}
}
*/
//Increase particles to rear thrusts
theParticleSystem = rightThruster.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 300);
theParticleSystem.rate = theParticleSystemsRateCurve;
theParticleSystem = leftThruster.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 300);
theParticleSystem.rate = theParticleSystemsRateCurve;
/*
//Try to apply some amount of backward velocity
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.up.x, -transform.up.y)));
if (angleDifference < 90) {
velocityToCheck = /*-transform.up*//* moveAngleInput * (1 - angleDifference / 90) * backwardAccel * Time.deltaTime;
//float currentSpeed = myVelocity.y * -transform.up.y + myVelocity.x * -transform.up.x;
float newSpeed = (myVelocity.y + velocityToCheck.y) * -transform.up.y + (myVelocity.x + velocityToCheck.x) * -transform.up.x;
//Don't add it if it puts you over the speed limit
if (newSpeed < backwardSpeedLimit * (1 - angleDifference / 90)) {
velocityToAdd += velocityToCheck;
}
}*/
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.up.x, -transform.up.y)));
if (angleDifference < 90) {
velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * backwardAccel * Time.deltaTime;
}
//Increase particles to front thrusts
theParticleSystem = rightFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
theParticleSystem = leftFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
/*
//Try to apply some amount of rightward velocity
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.right.x, transform.right.y)));
if (angleDifference < 90) {
velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
//float currentSpeed = myVelocity.y * transform.right.y + myVelocity.x * transform.right.x;
float newSpeed = (myVelocity.y + velocityToCheck.y) * transform.right.y + (myVelocity.x + velocityToCheck.x) * transform.right.x;
//Don't add it if it puts you over the speed limit
if (newSpeed < strafeSpeedLimit * (1 - angleDifference / 90)) {
velocityToAdd += velocityToCheck;
}
}*/
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (transform.right.x, transform.right.y)));
if (angleDifference < 90) {
velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
}
theParticleSystem = leftFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
/*
//Try to apply some amount of leftward velocity
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.right.x, -transform.right.y)));
if (angleDifference < 90) {
velocityToCheck = moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
//float currentSpeed = myVelocity.y * -transform.right.y + myVelocity.x * -transform.right.x;
float newSpeed = (myVelocity.y + velocityToCheck.y) * -transform.right.y + (myVelocity.x + velocityToCheck.x) * -transform.right.x;
//Debug.Log (newSpeed);
//Don't add it if it puts you over the speed limit
if (newSpeed < strafeSpeedLimit * (1 - angleDifference / 90)) {
velocityToAdd += velocityToCheck;
}
}*/
angleDifference = ( Vector2.Angle (moveAngleInput, new Vector2 (-transform.right.x, -transform.right.y)));
if (angleDifference < 90) {
velocityToAdd += moveAngleInput * (1 - angleDifference / 90) * strafeAccel * Time.deltaTime;
}
//Increase particles to front right thrusts
theParticleSystem = rightFrontThrust.GetComponent<ParticleSystem>().emission ;
theParticleSystemsRateCurve = theParticleSystem.rate;
theParticleSystemsRateCurve.constantMax += ((1 - angleDifference / 90) * 50) + 0;
theParticleSystem.rate = theParticleSystemsRateCurve;
//IMPROVE
//Ship accelerates slower at speed, similar to a plane
//Debug.Log(1.0f - (myVelocity.magnitude / maxSpeedMagnitude));
//velocityToAdd *= 1.5f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude - 4), 0.5f, 1f);//Old one
//velocityToAdd *= 1.5f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude - 4), 0.5f, 1f);//Better working one
//velocityToAdd *= 2f - Mathf.Clamp( (myVelocity.magnitude / maxSpeedMagnitude) * 1.5f, 1f, 1.5f);//Other decent alternative
//Slow acceleration
velocityToAdd *= (1 - percentageFrostSlow);
gameObject.GetComponent<Rigidbody2D> ().velocity += velocityToAdd;//Add the velocity
//Debug.Log (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude);
velocityToAdd = Vector2.zero;//Reset the velocity to add value, ready for the next update
//If the ship's velocity is above the max speed, it is reduced to the max speed instead.
if (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude > /*maxSpeedMagnitude*/ speedLimitToUse) {
gameObject.GetComponent<Rigidbody2D> ().velocity = gameObject.GetComponent<Rigidbody2D> ().velocity.normalized * speedLimitToUse;
}
//Debug.Log (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude);
//UNSURE
/*if (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude < 10f && moveAngleInput.magnitude < 0.5f) {
gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag + (1 - (gameObject.GetComponent<Rigidbody2D> ().velocity.magnitude / 10)) * 1.2f;
//gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag + 1;
} else
gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag;
*/
/*//stuff for recharging boost
remainingBoostRechargeDelay -= Time.deltaTime;
if (remainingBoostRechargeDelay <= 0) {
remainingBoostDuration += (maxBoostDuration / fullBoostRechargeTime) * Time.deltaTime;
if (remainingBoostDuration > maxBoostDuration)
remainingBoostDuration = maxBoostDuration;
}*/
}
public void addFrostStack (int stacksToAdd, float duration) {
frostStacks += stacksToAdd;
//Slows the player using a curve based on frostStacks / forstStacks^0.6. Look at the graph of (x / x^0.6) * 0.1 to see the percentage slow for x number of stacks
//https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=(x+%2F+x%5E0.6)+*+0.1
//Note that for laser drones, they may apply up to 10 stacks each
percentageFrostSlow = Mathf.Clamp((frostStacks / Mathf.Pow (frostStacks, 0.6f)) * 0.1f /*changed to half effect*/, 0f, 0.5f);
Debug.Log (frostStacks + " = " + percentageFrostSlow);
//Invoke a remove call for each stack after its duration has elapsed
for (int i = 0; i < stacksToAdd; i++) {
Invoke ("removeFrostStack", duration);
}
}
void removeFrostStack () {
frostStacks--;
if (frostStacks == 0) {
percentageFrostSlow = 0;
} else {
percentageFrostSlow = Mathf.Clamp ((frostStacks / Mathf.Pow (frostStacks, 0.6f)) * 0.1f, 0f, 0.5f);
}
Debug.Log (frostStacks + " = " + percentageFrostSlow);
}
void OnCollisionEnter2D (Collision2D hit) {
if (hit.gameObject.tag == "Wall") {
//Debug.Log((Vector3.Angle(hit.contacts [0].normal, transform.up) / 180));
gameObject.GetComponent<Rigidbody2D> ().drag = ((Vector3.Angle(hit.contacts [0].normal, transform.up) / 180) - 0.3f) * wallHitSlow * (myVelocity.magnitude / forwardSpeedLimit);
CancelInvoke("restoreDrag");
Invoke ("restoreDrag", 0.7f);
}
}
void restoreDrag() {
gameObject.GetComponent<Rigidbody2D> ().drag = originalDrag;
}
/*public void startBoost () {
boostButtonPressed = true;
}
public void stopBoost () {
boostButtonPressed = false;
}
public float getRemainingBoostPercent () {
return remainingBoostDuration / maxBoostDuration;
}*/
/*void ResetAxes(){ //this is used to calibrate the tilt control
zeroAc = Input.acceleration;
curAc = Vector3.zero;
}*/
}