Trick ehancements
This commit is contained in:
@@ -24,6 +24,11 @@ public class PlayerPickupController : MonoBehaviour
|
||||
public float pickupRange = 2.0f;
|
||||
|
||||
public GameObject heldObject;
|
||||
private Rigidbody2D heldBody;
|
||||
private float heldBodyMass;
|
||||
private float heldBodyGravity;
|
||||
private RigidbodyType2D heldBodyType;
|
||||
private bool heldBodySimulated;
|
||||
private PlayerPlatformerController platformerController;
|
||||
private PlayerStressController playerStressController;
|
||||
private bool isChargingThrow;
|
||||
@@ -163,9 +168,17 @@ public class PlayerPickupController : MonoBehaviour
|
||||
// Disable physics so it doesn't fall or collide with the player
|
||||
if (heldObject.TryGetComponent<Rigidbody2D>(out Rigidbody2D rb))
|
||||
{
|
||||
heldBody = rb;
|
||||
heldBodyMass = rb.mass;
|
||||
heldBodyGravity = rb.gravityScale;
|
||||
heldBodyType = rb.bodyType;
|
||||
heldBodySimulated = rb.simulated;
|
||||
|
||||
rb.simulated = false;
|
||||
rb.bodyType = RigidbodyType2D.Kinematic;
|
||||
rb.gravityScale = 0;
|
||||
rb.mass = 0;
|
||||
rb.gravityScale = 0f;
|
||||
rb.linearVelocity = Vector2.zero;
|
||||
rb.angularVelocity = 0f;
|
||||
}
|
||||
|
||||
if (trick != null)
|
||||
@@ -195,11 +208,14 @@ public class PlayerPickupController : MonoBehaviour
|
||||
void DropObject(bool applyThrow)
|
||||
{
|
||||
// Re-enable physics
|
||||
if (heldObject.TryGetComponent<Rigidbody2D>(out Rigidbody2D rb))
|
||||
if (heldBody != null)
|
||||
{
|
||||
rb.bodyType = RigidbodyType2D.Dynamic;
|
||||
rb.gravityScale = 1;
|
||||
rb.linearVelocity = Vector2.zero;
|
||||
heldBody.simulated = heldBodySimulated;
|
||||
heldBody.bodyType = heldBodyType;
|
||||
heldBody.gravityScale = heldBodyGravity;
|
||||
heldBody.mass = heldBodyMass;
|
||||
heldBody.linearVelocity = Vector2.zero;
|
||||
heldBody.angularVelocity = 0f;
|
||||
}
|
||||
if (heldObject.TryGetComponent<TrickController>(out var trick))
|
||||
{
|
||||
@@ -217,7 +233,7 @@ public class PlayerPickupController : MonoBehaviour
|
||||
heldPickup.enabled = true;
|
||||
}
|
||||
}
|
||||
if (applyThrow && heldObject.TryGetComponent<Rigidbody2D>(out Rigidbody2D throwBody))
|
||||
if (applyThrow && heldBody != null)
|
||||
{
|
||||
var direction = 1f;
|
||||
if (platformerController != null && Mathf.Abs(platformerController.LastMoveX) > 0.01f)
|
||||
@@ -231,8 +247,9 @@ public class PlayerPickupController : MonoBehaviour
|
||||
charge01 = Mathf.Clamp01(heldTime / Mathf.Max(0.01f, throwChargeTime));
|
||||
}
|
||||
var throwSpeed = Mathf.Lerp(minThrowSpeed, maxThrowSpeed, charge01);
|
||||
throwBody.linearVelocity = new Vector2(direction * throwSpeed, 0f);
|
||||
throwBody.angularVelocity = 0f;
|
||||
var upwardSpeed = throwUpwardForce * charge01;
|
||||
heldBody.linearVelocity = new Vector2(direction * throwSpeed, upwardSpeed);
|
||||
heldBody.angularVelocity = 0f;
|
||||
}
|
||||
heldObject.transform.position += Vector3.up * dropClearance;
|
||||
Collider2D col = heldObject.GetComponent<Collider2D>();
|
||||
@@ -241,6 +258,7 @@ public class PlayerPickupController : MonoBehaviour
|
||||
// Unparent
|
||||
heldObject.transform.SetParent(null);
|
||||
heldObject = null;
|
||||
heldBody = null;
|
||||
isChargingThrow = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user