blob: d3af00ec250a29354477b1bb8048609055cd147e (
plain)
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
|
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float force;
public float airControl = 0.3f;
public float extraDrag;
public float extraAngularDrag;
public float wallGrabDrag;
private CharacterData data;
private CharacterStatModifiers stats;
private float multiplier = 1f;
private void Start()
{
data = GetComponent<CharacterData>();
stats = GetComponent<CharacterStatModifiers>();
}
private void FixedUpdate()
{
if (!data.isPlaying)
{
return;
}
Move(data.input.direction);
if (data.isWallGrab && data.wallDistance < 0.7f)
{
Vector2 velocity = data.playerVel.velocity;
if (data.input.direction.y >= 0f)
{
_ = data.input.direction.x;
_ = 0f;
}
data.playerVel.velocity = velocity;
}
data.playerVel.velocity -= data.playerVel.velocity * TimeHandler.timeScale * 0.01f * 0.1f * extraDrag * multiplier;
data.playerVel.angularVelocity -= data.playerVel.angularVelocity * TimeHandler.timeScale * 0.01f * 0.1f * extraAngularDrag * multiplier;
}
private void Update()
{
}
public void Move(Vector2 direction)
{
UpdateMultiplier();
if (!data.isStunned)
{
direction.y = Mathf.Clamp(direction.y, -1f, 0f);
direction.y *= 2f;
data.playerVel.AddForce(direction * TimeHandler.timeScale * (1f - stats.GetSlow()) * stats.movementSpeed * force * data.playerVel.mass * 0.01f * multiplier, ForceMode2D.Force);
}
}
private void UpdateMultiplier()
{
multiplier = 1f;
if (!data.isGrounded)
{
multiplier = airControl;
}
}
}
|