I am working on a “fluid system” based on particles. I have the particles worked out but I am having trouble with a couple of things. The biggest is connecting the particles into a face, and the second is having spacing in between each particle. This is so that less particles can be used, and to help with volume. Here is the code I have at the moment:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Fluid: MonoBehaviour {
public float bonddist = 1;
public float bondStrength = 10;
public float repulsion = 10;
public float repulsionDist = 50;
public float damp = 1;
void Update ()
{
//Destroy (gameObject, 15);
Collider[] obj = Physics.OverlapSphere (transform.position, bonddist);
rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
foreach(Collider OBJ in obj)
{
GameObject temp = OBJ.gameObject;
Vector3 offset = transform.position - temp.transform.position;
Rigidbody rb = temp.rigidbody;
if((OBJ.tag == "Fluid") && Vector3.Distance(temp.transform.position, transform.position) > repulsionDist)
{
rb.AddForce(offset / bondStrength);
Debug.DrawLine(transform.position, temp.transform.position, Color.red);
}
else if(OBJ.tag == "Fluid")
{
rb.AddForce(-(offset / repulsion) / ((Vector3.Distance(temp.transform.position, transform.position)) + 0.0001f));
}
}
}
}