-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerControl.cs
More file actions
120 lines (92 loc) · 3.05 KB
/
playerControl.cs
File metadata and controls
120 lines (92 loc) · 3.05 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerControl : MonoBehaviour
{
public bool isOnGround = false;
public Rigidbody2D rb;
public LayerMask groundLayers;
public bool isRolling = false;
public float jumpForce = 600f;
public Transform checkPoint;
public float checkRadius = 0.2f;
public BoxCollider2D rollCol;
public float airControlMod = 5f;
public CapsuleCollider2D normalCol;
public bool facingRight;
private Vector3 vel = Vector3.zero;
public bool airControl = true;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
public void perform(float move, bool roll, bool jump) {
if (isOnGround) {
//THX BRACKEYS QALSO UNTIYJEFNUJRCVAERJTABSKBNGERFJBEURG RGJ ERTGJNSDFVUI FCVKsdH
// Move the character by finding the target velocity
Vector3 targetVelocity = new Vector2(move * 10f, rb.velocity.y);
// And then smoothing it out and applying it to the character
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref vel, 0.05f);
if (move > 0 && !facingRight)
{
// ... flip the player.
Flip();
}
// Otherwise if the input is moving the player left and the player is facing right...
else if (move < 0 && facingRight)
{
// ... flip the player.
Flip();
}
//thx brackeys :)
}
else if (!isOnGround && airControl) {
Vector3 targetVelocity = new Vector2(move * airControlMod, rb.velocity.y);
// And then smoothing it out and applying it to the character
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref vel, 0.05f);
if (move > 0 && !facingRight)
{
// ... flip the player.
Flip();
}
// Otherwise if the input is moving the player left and the player is facing right...
else if (move < 0 && facingRight)
{
// ... flip the player.
Flip();
}
//thx brackeys :)
}
if (isOnGround && jump) {
isOnGround = false;
rb.AddForce(new Vector2(0f, jumpForce));
}
if (roll) {
Vector3 targetVelocity = new Vector2(move * 20f, rb.velocity.y);
// And then smoothing it out and applying it to the character
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref vel, 0.05f);
}
}
void FixedUpdate() {
isOnGround = false;
//thx brackeys :) unity engine
Collider2D[] colliders = Physics2D.OverlapCircleAll(checkPoint.position, checkRadius, groundLayers);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].gameObject != gameObject)
{
isOnGround = true;
Debug.Log("n ground");
}
}
}
private void Flip()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
//brackeys is cool
}