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
public LayerMask mask;
// movement config
public float pushForce = 20f;
public float pushForce = 5f;
public float pushTime = 0.5f;
public float gravity = -15f;
public float runSpeed = 8f;
public float groundDamping = 20f; // how fast do we change direction? higher means faster
......@@ -41,6 +42,11 @@ public class PlayerControl : MonoBehaviour
// public float jumpWaitTime = 2.0;
[HideInInspector]
public Vector2 pushSpeed = Vector2.zero;
[HideInInspector]
public float lastPushStart = float.NegativeInfinity;
[HideInInspector]
public float rawMovementDirection = 1;
//[HideInInspector]
public float normalizedHorizontalSpeed = 0;
......@@ -83,16 +89,21 @@ public class PlayerControl : MonoBehaviour
}
}
void onControllerCollider(RaycastHit2D hit)
void OnCollisionEnter2D(Collision2D coll)
{
Rigidbody2D body = hit.collider.gameObject.GetComponent<Rigidbody2D>();
if (body)
{
//TODO abfrage " is dashing"
body.AddForce(moveDirection * pushForce);
if (coll.collider.tag != "Player" || !isDashing())
return;
PlayerControl other = coll.collider.gameObject.GetComponent<PlayerControl>();
other.setPushSpeed(currentDashDirection * pushForce);
lastDashStart = Time.time - dashCompletionTime;
currentDashCoolDown = dashCollisionCoolDown;
}
private void setPushSpeed(Vector2 pushSpeed)
{
this.pushSpeed = pushSpeed;
this.lastPushStart = Time.time;
}
void FixedUpdate()
......@@ -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:
body2D.velocity = velocity;
body2D.velocity = velocity + currentPushSpeed;
//update move direction after the currentposition was updated:
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