-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player_AddDodge.cs
122 lines (94 loc) · 2.47 KB
/
Player_AddDodge.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed;
float hAxis;
float vAxis;
bool wDown;
bool jDown;
bool dDown;
bool isJump;
bool isDodge;
Rigidbody rigid;
Animator anim;
Vector3 moveVec;
Vector3 DodgeVec;
void Start()
{
rigid = GetComponent<Rigidbody>();
anim = GetComponentInChildren<Animator>();
}
// Update is called once per frame
void Update()
{
GetInput();
Move();
Turn();
Jump();
Dodge();
}
void GetInput()
{
hAxis = Input.GetAxisRaw("Horizontal");
vAxis = Input.GetAxisRaw("Vertical");
//간단하게 hAxis, vAxis는 하나의 수직선이라고 보면 된다.
//이 상황에서는 Horizontal과 Vertical을 합쳐 x축과 z축을 만듬.
//Horizontal의 키보드 입력은 left와 right, Vertical은 up,down이다.
wDown = Input.GetButton("Walk");
jDown = Input.GetButtonDown("Jump");
dDown = Input.GetButtonDown("Dodge");
}
void Move()
{
moveVec = new Vector3(hAxis, 0, vAxis).normalized;
if(isDodge)
{
moveVec = DodgeVec;
}
transform.position += moveVec * speed * (wDown ? 0.3f : 1f) * Time.deltaTime;
//걷는 속도 느리게 설정
anim.SetBool("isRun", moveVec != Vector3.zero);
anim.SetBool("isWalk", wDown);
}
void Turn()
{
transform.LookAt(transform.position + moveVec);
//플레이어 보는 방향 설정
}
void Jump()
{
if(jDown && !isJump && !isDodge)
{
rigid.AddForce(Vector3.up * 15, ForceMode.Impulse);
anim.SetBool("isJump", true);
anim.SetTrigger("doJump");
isJump = true;
}
}
void Dodge()
{
if(dDown && moveVec != Vector3.zero && !isJump && !isDodge)
{
DodgeVec = moveVec;
speed *= 2;
anim.SetTrigger("doDodge");
isDodge = true;
Invoke("DodgeOut",0.4f);
}
}
void DodgeOut()
{
speed *= 0.5f;
isDodge = false;
}
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Floor")
{
isJump = false;
anim.SetBool("isJump",false);
}
}
}