Add blood drips while walking
This commit is contained in:
parent
4898d2c435
commit
8005b41f59
38
Assets/Scripts/Effects/BloodDripper.cs
Normal file
38
Assets/Scripts/Effects/BloodDripper.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Saltosion.OneWeapon {
|
||||||
|
public class BloodDripper : MonoBehaviour {
|
||||||
|
public Vector2 DripOffset = new Vector2(0, -0.5f);
|
||||||
|
public int DripCount = 5;
|
||||||
|
public float DropInterval = 0.5f;
|
||||||
|
|
||||||
|
private Rigidbody2D ParentBody;
|
||||||
|
private int Drips = 0;
|
||||||
|
private bool Step = false;
|
||||||
|
private float LastDropTime;
|
||||||
|
|
||||||
|
private void Start() {
|
||||||
|
ParentBody = transform.parent.GetComponent<Rigidbody2D>();
|
||||||
|
DropInterval *= Random.value + 0.5f;
|
||||||
|
LastDropTime = Random.value * DropInterval + Time.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update() {
|
||||||
|
if (ParentBody.velocity.magnitude > 0.1 && Time.time - LastDropTime > DropInterval) {
|
||||||
|
Step = !Step;
|
||||||
|
bool WalkingSideWays = Mathf.Abs(Vector2.Dot(ParentBody.velocity, new Vector2(1, 0))) > 0.5;
|
||||||
|
Vector2 Offset = DripOffset + new Vector2(-ParentBody.velocity.y, ParentBody.velocity.x).normalized *
|
||||||
|
(WalkingSideWays ? 0.1f : 0.2f) *
|
||||||
|
(Step ? 1f : -1f);
|
||||||
|
BloodLauncher.Splatter(ParentBody.position + Offset, Vector2.zero, 1 + (int)(Random.value * 5), 0f, 360f, false);
|
||||||
|
Drips++;
|
||||||
|
if (Drips >= DripCount) {
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
LastDropTime = Time.time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Effects/BloodDripper.cs.meta
Normal file
11
Assets/Scripts/Effects/BloodDripper.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4d1575b7aca5970469125348cb12707d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -12,15 +12,15 @@ namespace Saltosion.OneWeapon {
|
|||||||
public int MaxParticles;
|
public int MaxParticles;
|
||||||
public bool DebugLaunch = false;
|
public bool DebugLaunch = false;
|
||||||
|
|
||||||
public static void Splatter(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
public static void Splatter(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky = true) {
|
||||||
LaunchParticles(Singleton.GetGorePrefab(), origin, direction, particleCount, force, degrees);
|
LaunchParticles(Singleton.GetGorePrefab(), origin, direction, particleCount, force, degrees, sticky);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DebrisExplode(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
public static void DebrisExplode(Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky = true) {
|
||||||
LaunchParticles(Singleton.StructuralParticlePrefab, origin, direction, particleCount, force, degrees);
|
LaunchParticles(Singleton.StructuralParticlePrefab, origin, direction, particleCount, force, degrees, sticky);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LaunchParticles(GameObject prefab, Vector2 origin, Vector2 direction, int particleCount, float force, float degrees) {
|
private static void LaunchParticles(GameObject prefab, Vector2 origin, Vector2 direction, int particleCount, float force, float degrees, bool sticky) {
|
||||||
for (int i = 0; i < (int)(particleCount * Singleton.GetParticleCountMultiplier()); i++) {
|
for (int i = 0; i < (int)(particleCount * Singleton.GetParticleCountMultiplier()); i++) {
|
||||||
if (Singleton.ParticleRoot.childCount >= Singleton.MaxParticles) {
|
if (Singleton.ParticleRoot.childCount >= Singleton.MaxParticles) {
|
||||||
Destroy(Singleton.ParticleRoot.GetChild((int)(Random.value * Singleton.ParticleRoot.childCount)).gameObject);
|
Destroy(Singleton.ParticleRoot.GetChild((int)(Random.value * Singleton.ParticleRoot.childCount)).gameObject);
|
||||||
@ -32,6 +32,7 @@ namespace Saltosion.OneWeapon {
|
|||||||
float Offset = Mathf.Atan2(direction.y, direction.x);
|
float Offset = Mathf.Atan2(direction.y, direction.x);
|
||||||
float Radians = Offset + Mathf.Pow(Cone * (Random.value - 0.5f) * 2f, 2f) * Mathf.PI * 2.0f;
|
float Radians = Offset + Mathf.Pow(Cone * (Random.value - 0.5f) * 2f, 2f) * Mathf.PI * 2.0f;
|
||||||
Particle.LaunchForce = new Vector2(Mathf.Cos(Radians), Mathf.Sin(Radians)) * Intensity;
|
Particle.LaunchForce = new Vector2(Mathf.Cos(Radians), Mathf.Sin(Radians)) * Intensity;
|
||||||
|
Particle.GetsStuck = sticky && Random.value < 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,16 +8,15 @@ namespace Saltosion.OneWeapon {
|
|||||||
|
|
||||||
public Vector2 LaunchForce = new Vector2();
|
public Vector2 LaunchForce = new Vector2();
|
||||||
public bool Settled = false;
|
public bool Settled = false;
|
||||||
|
public bool GetsStuck = true;
|
||||||
public Sprite[] Sprites;
|
public Sprite[] Sprites;
|
||||||
|
|
||||||
private Rigidbody2D CurrentlyStuckOn = null;
|
private Rigidbody2D CurrentlyStuckOn = null;
|
||||||
private Vector2 Velocity;
|
private Vector2 Velocity;
|
||||||
private bool GetsStuck;
|
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
transform.localScale = new Vector2(0.02f, 0.02f) + Random.value * new Vector2(0.10f, 0.10f);
|
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);
|
Velocity = LaunchForce + new Vector2(Random.value - 0.5f, Random.value - 0.5f);
|
||||||
GetsStuck = Random.value > 0.5;
|
|
||||||
if (Sprites.Length > 0) {
|
if (Sprites.Length > 0) {
|
||||||
Renderer.sprite = Sprites[(int)(Random.value * int.MaxValue) % Sprites.Length];
|
Renderer.sprite = Sprites[(int)(Random.value * int.MaxValue) % Sprites.Length];
|
||||||
Renderer.flipX = Random.value < 0.5;
|
Renderer.flipX = Random.value < 0.5;
|
||||||
@ -35,6 +34,10 @@ namespace Saltosion.OneWeapon {
|
|||||||
if (CurrentlyStuckOn != null && GetsStuck) {
|
if (CurrentlyStuckOn != null && GetsStuck) {
|
||||||
transform.parent = CurrentlyStuckOn.transform;
|
transform.parent = CurrentlyStuckOn.transform;
|
||||||
GetComponentInChildren<SpriteRenderer>().sortingLayerName = "Blood Particles (On characters)";
|
GetComponentInChildren<SpriteRenderer>().sortingLayerName = "Blood Particles (On characters)";
|
||||||
|
if (transform.parent.tag == "Player" && Random.value < 0.5) {
|
||||||
|
// Half of all blood particles are "drippy" so they drip away over time on the floor
|
||||||
|
gameObject.AddComponent(typeof(BloodDripper));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Destroy(GetComponent<BoxCollider2D>());
|
Destroy(GetComponent<BoxCollider2D>());
|
||||||
Destroy(this);
|
Destroy(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user