Skip to content

Commit

Permalink
Kinda hacky fix for coins not disappearing after getting picked up wh…
Browse files Browse the repository at this point in the history
…ile falling
  • Loading branch information
jonuy committed Jul 19, 2014
1 parent ea0a75d commit 933b4a6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Assets/Scripts/CoinController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class CoinController : MonoBehaviour {

private float pickupFinalYPos;

private float pickupTimeRemaining = 1;

private void Awake() {
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
}
Expand All @@ -40,9 +42,13 @@ public void FixedUpdate() {
rigidbody2D.velocity = new Vector2(transform.localScale.x * velocity, rigidbody2D.velocity.y);

if (doPickup) {
// Kinda hacky, but keeping this timer to also ensure coin gets destroyed
// if it doesn't do the pickup movement in the right direction.
pickupTimeRemaining -= Time.deltaTime;

// If the position of the coin not within some threshold, then continue animating
float deltaY = Mathf.Abs(pickupFinalYPos - transform.position.y);
if (deltaY > 0.25) {
if (deltaY > 0.25 && pickupTimeRemaining > 0) {
float incrementalY = Mathf.Lerp(transform.position.y, pickupFinalYPos, Time.deltaTime * smoothingValue);
transform.position = new Vector3(transform.position.x, incrementalY, transform.position.z);
}
Expand Down

0 comments on commit 933b4a6

Please sign in to comment.