cleaned up scripts a little bit
This commit is contained in:
@@ -23,18 +23,11 @@ public class PlayerMovement : MonoBehaviour
|
||||
public Vector2 boxSize;
|
||||
public float maxDistanceFromGround;
|
||||
|
||||
[Header("Grappling:")]
|
||||
[SerializeField] public Tutorial_GrapplingGun grapplingGun;
|
||||
[SerializeField] public Tutorial_GrapplingRope grapplingRope;
|
||||
private GameObject grappleSurface;
|
||||
|
||||
[Header("Tambourine:")]
|
||||
[SerializeField] private Launch launcher;
|
||||
[HideInInspector] public bool hasTambourine = true;
|
||||
|
||||
[Header("State Control:")]
|
||||
[SerializeField] private StateController stateController;
|
||||
|
||||
PlayerBehavior playerBehavior;
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
this.runAcceleration = Mathf.Clamp(runAcceleration, 0.1f, this.maxRunSpeed);
|
||||
@@ -42,6 +35,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
playerBehavior = this.gameObject.GetComponent<PlayerBehavior>();
|
||||
this.rb = this.GetComponent<Rigidbody2D>();
|
||||
stateController = GameObject.Find("StateController").GetComponent<StateController>();
|
||||
}
|
||||
@@ -88,14 +82,16 @@ public class PlayerMovement : MonoBehaviour
|
||||
float frictionAmount = 0.5f;
|
||||
|
||||
// accelerate
|
||||
if (onGround && (Mathf.Abs(this.movement.x) > 0.1f)) {
|
||||
if (onGround && (Mathf.Abs(this.movement.x) > 0.1f)) { // regular acceleration
|
||||
this.rb.AddForce(move * Vector2.right, ForceMode2D.Force);
|
||||
} else if (!onGround && (Mathf.Abs(this.movement.x) > 0.1f)) {
|
||||
} else if (!onGround && (Mathf.Abs(this.movement.x) > 0.1f) && !playerBehavior.grapplingRope.isGrappling) { // while in air
|
||||
this.rb.AddForce(move * Vector2.right * airSpeedMultiplier, ForceMode2D.Force);
|
||||
} else if (!playerBehavior.grapplingRope.isGrappling) { // while grappling
|
||||
this.rb.AddForce(move * Vector2.right * airSpeedMultiplier * airSpeedMultiplier, ForceMode2D.Force);
|
||||
}
|
||||
|
||||
// decelerate until stopped
|
||||
if (Mathf.Abs(this.movement.x) < 0.1f)
|
||||
if (onGround && Mathf.Abs(this.movement.x) < 0.1f)
|
||||
{
|
||||
if (Mathf.Abs(rb.velocity.x) > 0.1f) {
|
||||
float amount = Mathf.Min(
|
||||
@@ -110,27 +106,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col)
|
||||
{
|
||||
if (col.tag == "grappleSurface")
|
||||
{
|
||||
grappleSurface = col.gameObject;
|
||||
}
|
||||
else if (col.tag == "instaDeath")
|
||||
{
|
||||
this.stateController.SetDeathCanvasActive(true);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D col)
|
||||
{
|
||||
if (col.tag == "grappleSurface")
|
||||
{
|
||||
grappleSurface = null;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsGrounded()
|
||||
{
|
||||
if (Physics2D.BoxCast(transform.position, boxSize, 0, -transform.up, maxDistanceFromGround, groundLayer))
|
||||
|
||||
Reference in New Issue
Block a user