grenouille assets
This commit is contained in:
@@ -156,6 +156,11 @@ public class PlayerBehavior : MonoBehaviour
|
||||
stateController.spawnPoint.GetComponent<SpawnPointBehavior>().DeactivateSpawnPoint();
|
||||
col.GetComponent<SpawnPointBehavior>().ActivateSpawnPoint();
|
||||
}
|
||||
else if (col.tag == "Trumpet")
|
||||
{
|
||||
this.playerController.in_range = true;
|
||||
this.playerController.enemy = col.transform.parent.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D col)
|
||||
@@ -164,6 +169,11 @@ public class PlayerBehavior : MonoBehaviour
|
||||
{
|
||||
grappleSurface = null;
|
||||
}
|
||||
else if (col.tag == "Trumpet")
|
||||
{
|
||||
this.playerController.in_range = true;
|
||||
this.playerController.enemy = null;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision) {
|
||||
|
||||
@@ -9,7 +9,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
public float runAcceleration;
|
||||
public float snappiness = 1;
|
||||
public float jumpSpeed;
|
||||
[Range(0,1)] public float airSpeedMultiplier;
|
||||
[Range(0, 1)] public float airSpeedMultiplier;
|
||||
private bool onGround = false;
|
||||
private float forward = 1;
|
||||
|
||||
@@ -23,6 +23,10 @@ public class PlayerMovement : MonoBehaviour
|
||||
public Vector2 boxSize;
|
||||
public float maxDistanceFromGround;
|
||||
|
||||
private bool trumpet = false;
|
||||
public bool in_range = false;
|
||||
public GameObject enemy;
|
||||
|
||||
[Header("State Control:")]
|
||||
[SerializeField] private StateController stateController;
|
||||
|
||||
@@ -46,10 +50,26 @@ public class PlayerMovement : MonoBehaviour
|
||||
//Debug.Log(this.movement);
|
||||
}
|
||||
|
||||
void OnJump() {
|
||||
if (IsGrounded()) {
|
||||
void OnJump()
|
||||
{
|
||||
if (IsGrounded())
|
||||
{
|
||||
//need to add a condition so that trumpet is only true in certain scenes
|
||||
trumpet = true;
|
||||
rb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
||||
}
|
||||
else if (!IsGrounded() && in_range && trumpet)
|
||||
{
|
||||
Destroy(enemy.gameObject);
|
||||
rb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
||||
enemy = null;
|
||||
in_range = false;
|
||||
}
|
||||
else if (!IsGrounded() && trumpet && !in_range)
|
||||
{
|
||||
rb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
||||
trumpet = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
@@ -82,25 +102,33 @@ public class PlayerMovement : MonoBehaviour
|
||||
float frictionAmount = 0.5f;
|
||||
|
||||
// accelerate
|
||||
if (onGround && (Mathf.Abs(this.movement.x) > 0.1f)) { // regular acceleration
|
||||
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) && !playerBehavior.grapplingRope.isGrappling) { // while in air
|
||||
}
|
||||
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
|
||||
}
|
||||
else if (!playerBehavior.grapplingRope.isGrappling)
|
||||
{ // while grappling
|
||||
this.rb.AddForce(move * Vector2.right * airSpeedMultiplier * airSpeedMultiplier, ForceMode2D.Force);
|
||||
}
|
||||
|
||||
// decelerate until stopped
|
||||
if (onGround && Mathf.Abs(this.movement.x) < 0.1f)
|
||||
{
|
||||
if (Mathf.Abs(rb.velocity.x) > 0.1f) {
|
||||
if (Mathf.Abs(rb.velocity.x) > 0.1f)
|
||||
{
|
||||
float amount = Mathf.Min(
|
||||
Mathf.Abs(this.rb.velocity.x),
|
||||
Mathf.Abs(frictionAmount)
|
||||
);
|
||||
amount *= Mathf.Sign(this.rb.velocity.x);
|
||||
this.rb.AddForce(-amount * Vector2.right * snappiness, ForceMode2D.Impulse);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rb.velocity = new Vector2(0, rb.velocity.y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user