|
|
|
|
|
|
using Unity.Physics.Systems; |
|
|
|
using Unity.Physics; |
|
|
|
|
|
|
|
[UpdateAfter(typeof(GertsnerSystem)), UpdateAfter(typeof(ExportPhysicsWorld))] |
|
|
|
[UpdateAfter(typeof(GertsnerSystem)), UpdateBefore(typeof(BuildPhysicsWorld))] |
|
|
|
public class ApplyBuoyancyForceSystem : JobComponentSystem |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
DynamicBuffer<VoxelOffset> offsets = offsetBuffer[entity]; |
|
|
|
DynamicBuffer<VoxelHeight> heights = heightBuffer[entity]; |
|
|
|
|
|
|
|
var vel2 = vel; |
|
|
|
|
|
|
|
Debug.Log("new pass: " + entity.ToString()); |
|
|
|
//Debug.Log("new pass: " + entity.ToString());
|
|
|
|
var entityTransform = new RigidTransform(rot.Value, pos.Value); |
|
|
|
var wp = pos.Value + offsets[i].Value; |
|
|
|
var wp = math.transform(entityTransform, offsets[i].Value); |
|
|
|
float waterLevel = heights[i].Value.y; |
|
|
|
|
|
|
|
if (wp.y - data.voxelResolution < waterLevel) |
|
|
|
|
|
|
|
|
|
|
submergedAmount += subFactor;//(math.clamp(waterLevel - (wp.y - voxelResolution), 0f, voxelResolution * 2f) / (voxelResolution * 2f)) / voxels.Count;
|
|
|
|
submergedAmount += subFactor / offsets.Length;//(math.clamp(waterLevel - (wp.y - voxelResolution), 0f, voxelResolution * 2f) / (voxelResolution * 2f)) / voxels.Count;
|
|
|
|
|
|
|
|
//var force2 = data.localArchimedesForce * subFactor;
|
|
|
|
|
|
|
|
|
|
|
var localDampingForce = .005f * math.rcp(mass.InverseMass) * -velocity; |
|
|
|
var force = localDampingForce + math.sqrt(subFactor) * data.localArchimedesForce;//\
|
|
|
|
ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, force * dt, wp); |
|
|
|
Debug.DrawLine(wp, force * dt + wp); |
|
|
|
Debug.Log(string.Format("Position: {0:f1} -- Force: {1:f2} -- Height: {2:f2}\nVelocty: {3:f2} -- Damp: {4:f2} -- Mass: {5:f1} -- K: {6:f2}", wp, force, waterLevel, velocity, localDampingForce, math.rcp(mass.InverseMass), dt)); |
|
|
|
//entity.ApplyImpulse(force, wp);//RB.AddForceAtPosition(force, wp);
|
|
|
|
|
|
|
|
//Debug.Log(string.Format("ECS: Position: {0:f1} -- Force: {1:f2} -- Height: {2:f2}\nVelocty: {3:f2} -- Damp: {4:f2} -- Mass: {5:f1} -- K: {6:f2}", wp, force, waterLevel, velocity, localDampingForce, math.rcp(mass.InverseMass), dt));
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|