Commit 6f542fd8 by Philipp Adolf

Make pushing other players work again

Also change push force of player prefabs to 5
parent 068d5b57
...@@ -16,7 +16,8 @@ public class PlayerControl : MonoBehaviour ...@@ -16,7 +16,8 @@ public class PlayerControl : MonoBehaviour
public LayerMask mask; public LayerMask mask;
// movement config // movement config
public float pushForce = 20f; public float pushForce = 5f;
public float pushTime = 0.5f;
public float gravity = -15f; public float gravity = -15f;
public float runSpeed = 8f; public float runSpeed = 8f;
public float groundDamping = 20f; // how fast do we change direction? higher means faster public float groundDamping = 20f; // how fast do we change direction? higher means faster
...@@ -41,6 +42,11 @@ public class PlayerControl : MonoBehaviour ...@@ -41,6 +42,11 @@ public class PlayerControl : MonoBehaviour
// public float jumpWaitTime = 2.0; // public float jumpWaitTime = 2.0;
[HideInInspector] [HideInInspector]
public Vector2 pushSpeed = Vector2.zero;
[HideInInspector]
public float lastPushStart = float.NegativeInfinity;
[HideInInspector]
public float rawMovementDirection = 1; public float rawMovementDirection = 1;
//[HideInInspector] //[HideInInspector]
public float normalizedHorizontalSpeed = 0; public float normalizedHorizontalSpeed = 0;
...@@ -83,16 +89,21 @@ public class PlayerControl : MonoBehaviour ...@@ -83,16 +89,21 @@ public class PlayerControl : MonoBehaviour
} }
} }
void onControllerCollider(RaycastHit2D hit) void OnCollisionEnter2D(Collision2D coll)
{ {
Rigidbody2D body = hit.collider.gameObject.GetComponent<Rigidbody2D>(); if (coll.collider.tag != "Player" || !isDashing())
if (body) return;
{
//TODO abfrage " is dashing" PlayerControl other = coll.collider.gameObject.GetComponent<PlayerControl>();
body.AddForce(moveDirection * pushForce); other.setPushSpeed(currentDashDirection * pushForce);
lastDashStart = Time.time - dashCompletionTime; lastDashStart = Time.time - dashCompletionTime;
currentDashCoolDown = dashCollisionCoolDown; currentDashCoolDown = dashCollisionCoolDown;
} }
private void setPushSpeed(Vector2 pushSpeed)
{
this.pushSpeed = pushSpeed;
this.lastPushStart = Time.time;
} }
void FixedUpdate() void FixedUpdate()
...@@ -164,9 +175,15 @@ public class PlayerControl : MonoBehaviour ...@@ -164,9 +175,15 @@ public class PlayerControl : MonoBehaviour
} }
} }
float currentPushTime = Time.time - lastPushStart;
Vector2 currentPushSpeed = Vector2.zero;
if (0 <= currentPushTime && currentPushTime <= pushTime)
{
currentPushSpeed = Vector2.Lerp(pushSpeed, Vector2.zero, currentPushTime / pushTime);
}
//finally set the velocity: //finally set the velocity:
body2D.velocity = velocity; body2D.velocity = velocity + currentPushSpeed;
//update move direction after the currentposition was updated: //update move direction after the currentposition was updated:
moveDirection = (transform.position - lastPos).normalized; moveDirection = (transform.position - lastPos).normalized;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment