浏览代码

-Getting closer to physical parity

/dots-input
Mike Geig 5 年前
当前提交
df3550fe
共有 3 个文件被更改,包括 321 次插入132 次删除
  1. 10
      Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs
  2. 4
      Assets/Unity Physics Items/BuoyantObject2.cs
  3. 439
      Assets/Unity Physics Items/Physics Scene.unity

10
Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs


DynamicBuffer<VoxelHeight> heights = heightBuffer[entity];
float submergedAmount = 0f;
Debug.Log("new pass: " + entity.ToString());
//Apply buoyant force
for (var i = 0; i < offsets.Length; i++)
{

velocity.y *= 2f;
var localDampingForce = .005f * math.rcp(mass.InverseMass) * -velocity;
var force = localDampingForce + math.sqrt(k) * data.localArchimedesForce;//\
ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, force * dt, wp);
ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, force * dt * dt, wp);
Debug.Log("Vel: " + vel.Linear.ToString() + " Force: " + force);
//Debug.Log(string.Format("B Position: {0} -- Force: {1}", wp.ToString(), force.ToString()));
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), data.localArchimedesForce));
data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
//data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
//RB.drag = data.baseDrag + (data.baseDrag * (data.percentSubmerged * 10f));
//RB.angularDrag = data.baseAngularDrag + (data.percentSubmerged * 0.5f);

4
Assets/Unity Physics Items/BuoyantObject2.cs


public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
Init();
BuoyantData data = new BuoyantData();
data.type = _buoyancyType;
data.voxelResolution = voxelResolution;

for (int i = 0; i < voxels.Length; i++)
{
offsets.Add(new VoxelOffset { Value = transform.position - transform.TransformPoint(voxels[i]) });
offsets.Add(new VoxelOffset { Value = transform.TransformPoint(voxels[i]) - transform.position });
heights.Add(new VoxelHeight { Value = float3.zero });
}
}

439
Assets/Unity Physics Items/Physics Scene.unity


_buoyancyType: 3
density: 640
volume: 1
voxelResolution: 0.2
voxelResolution: 0.5
- {x: -0.4, y: -0.4, z: -0.4}
- {x: -0.4, y: -0.4, z: -0.20000002}
- {x: -0.4, y: -0.4, z: -0.000000007450581}
- {x: -0.4, y: -0.4, z: 0.19999999}
- {x: -0.4, y: -0.4, z: 0.4}
- {x: -0.4, y: -0.20000002, z: -0.4}
- {x: -0.4, y: -0.20000002, z: -0.20000002}
- {x: -0.4, y: -0.20000002, z: -0.000000007450581}
- {x: -0.4, y: -0.20000002, z: 0.19999999}
- {x: -0.4, y: -0.20000002, z: 0.4}
- {x: -0.4, y: -0.000000007450581, z: -0.4}
- {x: -0.4, y: -0.000000007450581, z: -0.20000002}
- {x: -0.4, y: -0.000000007450581, z: -0.000000007450581}
- {x: -0.4, y: -0.000000007450581, z: 0.19999999}
- {x: -0.4, y: -0.000000007450581, z: 0.4}
- {x: -0.4, y: 0.19999999, z: -0.4}
- {x: -0.4, y: 0.19999999, z: -0.20000002}
- {x: -0.4, y: 0.19999999, z: -0.000000007450581}
- {x: -0.4, y: 0.19999999, z: 0.19999999}
- {x: -0.4, y: 0.19999999, z: 0.4}
- {x: -0.4, y: 0.4, z: -0.4}
- {x: -0.4, y: 0.4, z: -0.20000002}
- {x: -0.4, y: 0.4, z: -0.000000007450581}
- {x: -0.4, y: 0.4, z: 0.19999999}
- {x: -0.4, y: 0.4, z: 0.4}
- {x: -0.20000002, y: -0.4, z: -0.4}
- {x: -0.20000002, y: -0.4, z: -0.20000002}
- {x: -0.20000002, y: -0.4, z: -0.000000007450581}
- {x: -0.20000002, y: -0.4, z: 0.19999999}
- {x: -0.20000002, y: -0.4, z: 0.4}
- {x: -0.20000002, y: -0.20000002, z: -0.4}
- {x: -0.20000002, y: -0.20000002, z: -0.20000002}
- {x: -0.20000002, y: -0.20000002, z: -0.000000007450581}
- {x: -0.20000002, y: -0.20000002, z: 0.19999999}
- {x: -0.20000002, y: -0.20000002, z: 0.4}
- {x: -0.20000002, y: -0.000000007450581, z: -0.4}
- {x: -0.20000002, y: -0.000000007450581, z: -0.20000002}
- {x: -0.20000002, y: -0.000000007450581, z: -0.000000007450581}
- {x: -0.20000002, y: -0.000000007450581, z: 0.19999999}
- {x: -0.20000002, y: -0.000000007450581, z: 0.4}
- {x: -0.20000002, y: 0.19999999, z: -0.4}
- {x: -0.20000002, y: 0.19999999, z: -0.20000002}
- {x: -0.20000002, y: 0.19999999, z: -0.000000007450581}
- {x: -0.20000002, y: 0.19999999, z: 0.19999999}
- {x: -0.20000002, y: 0.19999999, z: 0.4}
- {x: -0.20000002, y: 0.4, z: -0.4}
- {x: -0.20000002, y: 0.4, z: -0.20000002}
- {x: -0.20000002, y: 0.4, z: -0.000000007450581}
- {x: -0.20000002, y: 0.4, z: 0.19999999}
- {x: -0.20000002, y: 0.4, z: 0.4}
- {x: -0.000000007450581, y: -0.4, z: -0.4}
- {x: -0.000000007450581, y: -0.4, z: -0.20000002}
- {x: -0.000000007450581, y: -0.4, z: -0.000000007450581}
- {x: -0.000000007450581, y: -0.4, z: 0.19999999}
- {x: -0.000000007450581, y: -0.4, z: 0.4}
- {x: -0.000000007450581, y: -0.20000002, z: -0.4}
- {x: -0.000000007450581, y: -0.20000002, z: -0.20000002}
- {x: -0.000000007450581, y: -0.20000002, z: -0.000000007450581}
- {x: -0.000000007450581, y: -0.20000002, z: 0.19999999}
- {x: -0.000000007450581, y: -0.20000002, z: 0.4}
- {x: -0.000000007450581, y: -0.000000007450581, z: -0.4}
- {x: -0.000000007450581, y: -0.000000007450581, z: -0.20000002}
- {x: -0.000000007450581, y: -0.000000007450581, z: -0.000000007450581}
- {x: -0.000000007450581, y: -0.000000007450581, z: 0.19999999}
- {x: -0.000000007450581, y: -0.000000007450581, z: 0.4}
- {x: -0.000000007450581, y: 0.19999999, z: -0.4}
- {x: -0.000000007450581, y: 0.19999999, z: -0.20000002}
- {x: -0.000000007450581, y: 0.19999999, z: -0.000000007450581}
- {x: -0.000000007450581, y: 0.19999999, z: 0.19999999}
- {x: -0.000000007450581, y: 0.19999999, z: 0.4}
- {x: -0.000000007450581, y: 0.4, z: -0.4}
- {x: -0.000000007450581, y: 0.4, z: -0.20000002}
- {x: -0.000000007450581, y: 0.4, z: -0.000000007450581}
- {x: -0.000000007450581, y: 0.4, z: 0.19999999}
- {x: -0.000000007450581, y: 0.4, z: 0.4}
- {x: 0.19999999, y: -0.4, z: -0.4}
- {x: 0.19999999, y: -0.4, z: -0.20000002}
- {x: 0.19999999, y: -0.4, z: -0.000000007450581}
- {x: 0.19999999, y: -0.4, z: 0.19999999}
- {x: 0.19999999, y: -0.4, z: 0.4}
- {x: 0.19999999, y: -0.20000002, z: -0.4}
- {x: 0.19999999, y: -0.20000002, z: -0.20000002}
- {x: 0.19999999, y: -0.20000002, z: -0.000000007450581}
- {x: 0.19999999, y: -0.20000002, z: 0.19999999}
- {x: 0.19999999, y: -0.20000002, z: 0.4}
- {x: 0.19999999, y: -0.000000007450581, z: -0.4}
- {x: 0.19999999, y: -0.000000007450581, z: -0.20000002}
- {x: 0.19999999, y: -0.000000007450581, z: -0.000000007450581}
- {x: 0.19999999, y: -0.000000007450581, z: 0.19999999}
- {x: 0.19999999, y: -0.000000007450581, z: 0.4}
- {x: 0.19999999, y: 0.19999999, z: -0.4}
- {x: 0.19999999, y: 0.19999999, z: -0.20000002}
- {x: 0.19999999, y: 0.19999999, z: -0.000000007450581}
- {x: 0.19999999, y: 0.19999999, z: 0.19999999}
- {x: 0.19999999, y: 0.19999999, z: 0.4}
- {x: 0.19999999, y: 0.4, z: -0.4}
- {x: 0.19999999, y: 0.4, z: -0.20000002}
- {x: 0.19999999, y: 0.4, z: -0.000000007450581}
- {x: 0.19999999, y: 0.4, z: 0.19999999}
- {x: 0.19999999, y: 0.4, z: 0.4}
- {x: 0.4, y: -0.4, z: -0.4}
- {x: 0.4, y: -0.4, z: -0.20000002}
- {x: 0.4, y: -0.4, z: -0.000000007450581}
- {x: 0.4, y: -0.4, z: 0.19999999}
- {x: 0.4, y: -0.4, z: 0.4}
- {x: 0.4, y: -0.20000002, z: -0.4}
- {x: 0.4, y: -0.20000002, z: -0.20000002}
- {x: 0.4, y: -0.20000002, z: -0.000000007450581}
- {x: 0.4, y: -0.20000002, z: 0.19999999}
- {x: 0.4, y: -0.20000002, z: 0.4}
- {x: 0.4, y: -0.000000007450581, z: -0.4}
- {x: 0.4, y: -0.000000007450581, z: -0.20000002}
- {x: 0.4, y: -0.000000007450581, z: -0.000000007450581}
- {x: 0.4, y: -0.000000007450581, z: 0.19999999}
- {x: 0.4, y: -0.000000007450581, z: 0.4}
- {x: 0.4, y: 0.19999999, z: -0.4}
- {x: 0.4, y: 0.19999999, z: -0.20000002}
- {x: 0.4, y: 0.19999999, z: -0.000000007450581}
- {x: 0.4, y: 0.19999999, z: 0.19999999}
- {x: 0.4, y: 0.19999999, z: 0.4}
- {x: 0.4, y: 0.4, z: -0.4}
- {x: 0.4, y: 0.4, z: -0.20000002}
- {x: 0.4, y: 0.4, z: -0.000000007450581}
- {x: 0.4, y: 0.4, z: 0.19999999}
- {x: 0.4, y: 0.4, z: 0.4}
- {x: -0.25, y: -0.25, z: -0.25}
- {x: -0.25, y: -0.25, z: 0.25}
- {x: -0.25, y: 0.25, z: -0.25}
- {x: -0.25, y: 0.25, z: 0.25}
- {x: 0.25, y: -0.25, z: -0.25}
- {x: 0.25, y: -0.25, z: 0.25}
- {x: 0.25, y: 0.25, z: -0.25}
- {x: 0.25, y: 0.25, z: 0.25}
colliders:
- {fileID: 180195174}
percentSubmerged: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 180195171}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -103.65, y: 0.99, z: -2.92}
m_LocalPosition: {x: -103.65, y: -1.2, z: -2.92}
m_LocalScale: {x: 4.55, y: 0.73, z: 4.6}
m_Children: []
m_Father: {fileID: 0}

m_Father: {fileID: 324248881}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1240575472
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1240575473}
- component: {fileID: 1240575477}
- component: {fileID: 1240575476}
- component: {fileID: 1240575475}
- component: {fileID: 1240575474}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1240575473
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240575472}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1501079350}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1240575474
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240575472}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ea7d7495833204790ba1d3a8755397f8, type: 3}
m_Name:
m_EditorClassIdentifier:
ConversionMode: 1
--- !u!114 &1240575475
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240575472}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 80b5230fc040dc24a87a4b4792d30957, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!23 &1240575476
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240575472}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1240575477
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240575472}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1358838130
GameObject:
m_ObjectHideFlags: 0

- 364a025bae9c84dab8e79037a0d9b6a3: {fileID: 1881355361}
- a3e90ce987ce547e49d06c6e77144da8: {fileID: 96716009}
- 935fa36aa65fc463ebdd9d1e498083b1: {fileID: 681645759}
--- !u!1 &1501079342
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1501079350}
- component: {fileID: 1501079349}
- component: {fileID: 1501079348}
- component: {fileID: 1501079347}
- component: {fileID: 1501079346}
- component: {fileID: 1501079345}
- component: {fileID: 1501079344}
- component: {fileID: 1501079343}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1501079343
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ea7d7495833204790ba1d3a8755397f8, type: 3}
m_Name:
m_EditorClassIdentifier:
ConversionMode: 0
--- !u!114 &1501079344
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ccea9ea98e38942e0b0938c27ed1903e, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MotionType: 0
m_Mass: 640
m_LinearDamping: 0.1
m_AngularDamping: 0.05
m_InitialLinearVelocity:
x: 0
y: 0
z: 0
m_InitialAngularVelocity:
x: 0
y: 0
z: 0
m_GravityFactor: 1
m_OverrideDefaultMassDistribution: 0
m_CenterOfMass:
x: 0
y: 0
z: 0
m_Orientation:
Value:
x: 0
y: 0
z: 0
RotationOrder: 4
m_InertiaTensor:
x: 0.4
y: 0.4
z: 0.4
--- !u!114 &1501079345
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0fe52c158d195e64a99e4eaa38bb3df7, type: 3}
m_Name:
m_EditorClassIdentifier:
_buoyancyType: 3
density: 640
volume: 1
voxelResolution: 0.5
centerOfMass: {x: 0, y: 0, z: 0}
voxels:
- {x: -0.25, y: -0.25, z: -0.25}
- {x: -0.25, y: -0.25, z: 0.25}
- {x: -0.25, y: 0.25, z: -0.25}
- {x: -0.25, y: 0.25, z: 0.25}
- {x: 0.25, y: -0.25, z: -0.25}
- {x: 0.25, y: -0.25, z: 0.25}
- {x: 0.25, y: 0.25, z: -0.25}
- {x: 0.25, y: 0.25, z: 0.25}
colliders:
- {fileID: 1501079347}
percentSubmerged: 0
--- !u!54 &1501079346
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
serializedVersion: 2
m_Mass: 640
m_Drag: 0.1
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!65 &1501079347
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1501079348
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1501079349
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1501079350
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1501079342}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -103.65, y: -1.2, z: -2.92}
m_LocalScale: {x: 4.55, y: 0.73, z: 4.6}
m_Children:
- {fileID: 1240575473}
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1531988074 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3457973740146875416, guid: 0a308b87c1579fb4c9ea256406209ca5,

正在加载...
取消
保存