50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Saltosion.OneWeapon {
|
|||
|
public class BloodParticle : MonoBehaviour {
|
|||
|
public Vector2 LaunchForce = new Vector2();
|
|||
|
public bool Settled = false;
|
|||
|
|
|||
|
private Rigidbody2D CurrentlyStuckOn = null;
|
|||
|
private Vector2 Velocity;
|
|||
|
private bool GetsStuck;
|
|||
|
|
|||
|
private void Start() {
|
|||
|
transform.localScale = new Vector2(0.02f, 0.02f) + Random.value * new Vector2(0.10f, 0.10f);
|
|||
|
Velocity = LaunchForce + new Vector2(Random.value - 0.5f, Random.value - 0.5f);
|
|||
|
GetsStuck = Random.value > 0.5;
|
|||
|
}
|
|||
|
|
|||
|
private void FixedUpdate() {
|
|||
|
Velocity *= 1.0f - Time.fixedDeltaTime * 20.0f;
|
|||
|
if (CurrentlyStuckOn != null) {
|
|||
|
bool IsStatic = CurrentlyStuckOn.bodyType == RigidbodyType2D.Static;
|
|||
|
Velocity *= 1.0f - Time.fixedDeltaTime * (IsStatic ? 35.0f : 15.0f);
|
|||
|
}
|
|||
|
if (Velocity.magnitude < 0.1) {
|
|||
|
if (CurrentlyStuckOn != null && GetsStuck) {
|
|||
|
transform.parent = CurrentlyStuckOn.transform;
|
|||
|
}
|
|||
|
Destroy(GetComponent<BoxCollider2D>());
|
|||
|
Destroy(this);
|
|||
|
}
|
|||
|
|
|||
|
Vector2 AppliedMovement = Velocity * Time.fixedDeltaTime;
|
|||
|
|
|||
|
RaycastHit2D Hit = Physics2D.Raycast(transform.position, AppliedMovement, AppliedMovement.magnitude);
|
|||
|
if (Hit.collider != null) {
|
|||
|
bool IsStatic = Hit.rigidbody.bodyType == RigidbodyType2D.Static;
|
|||
|
Velocity = Velocity.normalized * Mathf.Min(IsStatic ? 15.0f : 60.0f, Velocity.magnitude);
|
|||
|
CurrentlyStuckOn = Hit.rigidbody;
|
|||
|
AppliedMovement = Velocity * Time.fixedDeltaTime;
|
|||
|
}
|
|||
|
|
|||
|
Vector2 NewPosition = (Vector2)transform.position + AppliedMovement;
|
|||
|
|
|||
|
transform.position = NewPosition;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|