浏览代码

-staging changes before reverting to older version for testing

/dots-input
Mike Geig 5 年前
当前提交
3efc38d6
共有 3 个文件被更改,包括 5 次插入18 次删除
  1. 13
      Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs
  2. 2
      Assets/Unity Physics Items/Physics Scene.unity
  3. 8
      Packages/com.verasl.water-system/Scripts/BuoyantObject.cs

13
Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs


float submergedAmount = 0f;
Debug.Log("new pass: " + entity.ToString());
float3 totalForce = float3.zero;
float3 averagePos = float3.zero;
int total = 0;
//Apply buoyant force
for (var i = 0; i < offsets.Length; i++)
{

if (wp.y - data.voxelResolution < waterLevel)
{
//float depth = waterLevel - wp.y + (data.voxelResolution * 2f);
float subFactor = Mathf.Clamp01(waterLevel - (wp.y - data.voxelResolution)) / (data.voxelResolution * 2f);//depth / data.voxelResolution);
float subFactor = Mathf.Clamp01((waterLevel - (wp.y - data.voxelResolution)) / (data.voxelResolution * 2f));//depth / data.voxelResolution);
submergedAmount += subFactor;//(math.clamp(waterLevel - (wp.y - voxelResolution), 0f, voxelResolution * 2f) / (voxelResolution * 2f)) / voxels.Count;

velocity.y *= 2f;
var localDampingForce = .005f * math.rcp(mass.InverseMass) * -velocity;
var force = localDampingForce + math.sqrt(subFactor) * data.localArchimedesForce;//\
totalForce += force;
averagePos += wp;
total++;
ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, force * dt, wp);
//entity.ApplyImpulse(force, wp);//RB.AddForceAtPosition(force, wp);

}
//if(total != 0)
//ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, totalForce / math.rcp(mass.InverseMass) * dt, averagePos / total);
Debug.Log("Total Force: " + totalForce);
//Update drag
//submergedAmount /= offsets.Length;

2
Assets/Unity Physics Items/Physics Scene.unity


m_GameObject: {fileID: 180195171}
serializedVersion: 2
m_Mass: 640
m_Drag: 0.1
m_Drag: 5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0

8
Packages/com.verasl.water-system/Scripts/BuoyantObject.cs


for(var i = 0; i < voxels.Length; i++) BuoyancyForce(voxels[i], heights[i].y, ref submergedAmount, ref debugInfo[i]);
Physics.SyncTransforms();
Physics.autoSyncTransforms = true;
UpdateDrag(submergedAmount);
// UpdateDrag(submergedAmount);
}
else if(_buoyancyType == BuoyancyType.Physical)
{

_debug.waterHeight = waterLevel;
_debug.force = Vector3.zero;
Vector3 force = Vector3.zero;
Vector3 totalForce = Vector3.zero;
float k = Mathf.Clamp01(waterLevel - (wp.y - voxelResolution)) / (voxelResolution * 2f);
float k = Mathf.Clamp01((waterLevel - (wp.y - voxelResolution)) / (voxelResolution * 2f));
submergedAmount += k / voxels.Length;//(math.clamp(waterLevel - (wp.y - voxelResolution), 0f, voxelResolution * 2f) / (voxelResolution * 2f)) / voxels.Count;
submergedAmount += k / voxels.Length;//(math.clamp(waterLevel - (wp.y - voxelResolution), 0f, voxelResolution * 2f) / (voxelResolution * 2f)) / voxels.Count;
var velocity = RB.GetPointVelocity(wp);
velocity.y *= 2f;

_debug.force = force; // For drawing force gizmos
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, RB.mass, localArchimedesForce));
}
Debug.Log("Total Force: " + totalForce);
}
private void UpdateDrag(float submergedAmount)

正在加载...
取消
保存