Tricks can now occupy baskets and block scoring
This commit is contained in:
@@ -46,6 +46,7 @@ public class TrickController : MonoBehaviour
|
||||
private Vector2 wanderDirection;
|
||||
private float nextWanderTime;
|
||||
private bool isCarried;
|
||||
private bool isBasketed;
|
||||
private float nextConsumeTime;
|
||||
private float desiredXVelocity;
|
||||
private float nextJumpTime;
|
||||
@@ -54,6 +55,19 @@ public class TrickController : MonoBehaviour
|
||||
private readonly RaycastHit2D[] wallHits = new RaycastHit2D[4];
|
||||
private float wallAvoidUntil;
|
||||
private float wallAvoidDirection;
|
||||
private RigidbodyType2D basketBodyType;
|
||||
private float basketGravityScale;
|
||||
private bool basketSimulated;
|
||||
private bool hasBasketAnchor;
|
||||
private Vector2 basketAnchorPosition;
|
||||
[SerializeField] private string basketSortingLayer = "";
|
||||
[SerializeField] private int basketSortingOrder = -10;
|
||||
private SpriteRenderer cachedRenderer;
|
||||
private string originalSortingLayer;
|
||||
private int originalSortingOrder;
|
||||
|
||||
public bool IsCarried => isCarried;
|
||||
public bool IsBasketed => isBasketed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -63,6 +77,7 @@ public class TrickController : MonoBehaviour
|
||||
body.freezeRotation = true;
|
||||
body.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
|
||||
body.interpolation = RigidbodyInterpolation2D.Interpolate;
|
||||
cachedRenderer = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -88,6 +103,11 @@ public class TrickController : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBasketed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var position = transform.position;
|
||||
if (position.x < despawnMinX || position.x > despawnMaxX || position.y < despawnMinY || position.y > despawnMaxY)
|
||||
{
|
||||
@@ -131,6 +151,19 @@ public class TrickController : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBasketed)
|
||||
{
|
||||
if (hasBasketAnchor)
|
||||
{
|
||||
transform.position = basketAnchorPosition;
|
||||
}
|
||||
var held = body.linearVelocity;
|
||||
held.x = 0f;
|
||||
held.y = 0f;
|
||||
body.linearVelocity = held;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time < movementLockUntil)
|
||||
{
|
||||
return;
|
||||
@@ -448,6 +481,10 @@ public class TrickController : MonoBehaviour
|
||||
public void SetCarried(bool carried)
|
||||
{
|
||||
isCarried = carried;
|
||||
if (carried && isBasketed)
|
||||
{
|
||||
SetBasketed(false);
|
||||
}
|
||||
if (carried)
|
||||
{
|
||||
target = null;
|
||||
@@ -475,6 +512,62 @@ public class TrickController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBasketed(bool basketed, Vector2? anchorPosition = null)
|
||||
{
|
||||
if (isBasketed == basketed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isBasketed = basketed;
|
||||
if (basketed)
|
||||
{
|
||||
if (cachedRenderer != null)
|
||||
{
|
||||
originalSortingLayer = cachedRenderer.sortingLayerName;
|
||||
originalSortingOrder = cachedRenderer.sortingOrder;
|
||||
if (!string.IsNullOrWhiteSpace(basketSortingLayer))
|
||||
{
|
||||
cachedRenderer.sortingLayerName = basketSortingLayer;
|
||||
}
|
||||
cachedRenderer.sortingOrder = basketSortingOrder;
|
||||
}
|
||||
if (anchorPosition.HasValue)
|
||||
{
|
||||
hasBasketAnchor = true;
|
||||
basketAnchorPosition = anchorPosition.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasBasketAnchor = false;
|
||||
}
|
||||
basketBodyType = body.bodyType;
|
||||
basketGravityScale = body.gravityScale;
|
||||
basketSimulated = body.simulated;
|
||||
body.simulated = true;
|
||||
body.bodyType = RigidbodyType2D.Kinematic;
|
||||
body.gravityScale = 0f;
|
||||
body.linearVelocity = Vector2.zero;
|
||||
body.angularVelocity = 0f;
|
||||
nextJumpTime = Time.time + 0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cachedRenderer != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(basketSortingLayer))
|
||||
{
|
||||
cachedRenderer.sortingLayerName = originalSortingLayer;
|
||||
}
|
||||
cachedRenderer.sortingOrder = originalSortingOrder;
|
||||
}
|
||||
hasBasketAnchor = false;
|
||||
body.simulated = basketSimulated;
|
||||
body.bodyType = basketBodyType;
|
||||
body.gravityScale = basketGravityScale;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnThrown()
|
||||
{
|
||||
movementLockUntil = Time.time + throwControlLockTime;
|
||||
|
||||
Reference in New Issue
Block a user