浏览代码

-Added code to control boat with dots physics and input. Forces not applying correctly yet

/dots-input
Mike Geig 5 年前
当前提交
c153ce71
共有 16 个文件被更改,包括 549 次插入122 次删除
  1. 334
      Assets/Objects/boats/Prefabs/_Boat.prefab
  2. 7
      Assets/Scripts/Boat/BoatController.cs
  3. 107
      Assets/Scripts/Boat/Engine.cs
  4. 4
      Assets/Scripts/Boat/HumanController.cs
  5. 11
      Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs
  6. 4
      Assets/Unity Physics Items/BuoyantObject2.cs
  7. 39
      Assets/Unity Physics Items/Physics Scene.unity
  8. 2
      Assets/Unity Physics Items/PhysicsConversionSystem.cs
  9. 18
      Assets/Unity Physics Items/BoatDriveSystem.cs
  10. 11
      Assets/Unity Physics Items/BoatDriveSystem.cs.meta
  11. 88
      Assets/Unity Physics Items/DriveSystem.cs
  12. 11
      Assets/Unity Physics Items/DriveSystem.cs.meta
  13. 9
      Assets/Unity Physics Items/DrivingData.cs
  14. 11
      Assets/Unity Physics Items/DrivingData.cs.meta
  15. 4
      Assets/Unity Physics Items/MoveWithInputTag.cs
  16. 11
      Assets/Unity Physics Items/MoveWithInputTag.cs.meta

334
Assets/Objects/boats/Prefabs/_Boat.prefab


- {fileID: 4603708908827592}
- {fileID: 4693301302057358}
- {fileID: 4416522625512240}
- {fileID: 4653116848354930}
m_Father: {fileID: 4603238648617514}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1489463026464572}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.002, z: -0.172}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.066, z: -3.9549997}
m_Father: {fileID: 1857749394586354482}
m_RootOrder: 0
m_Father: {fileID: 4226103850215974}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!198 &198499198857476844
ParticleSystem:

- component: {fileID: 64258884862185400}
- component: {fileID: 114129291822198474}
- component: {fileID: 114571606569623246}
- component: {fileID: 1169622266}
m_Layer: 11
m_Name: _Boat
m_TagString: boat

serializedVersion: 2
m_Mass: 3200
m_Drag: 0.1
m_AngularDrag: 0.05
m_AngularDrag: 0.2
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 1

m_EditorClassIdentifier:
Human: 0
RandomizeColors: 1
PrimaryColor: {r: 0.6359154, g: 0.60109407, b: 0.063591555, a: 1}
TrimColor: {r: 0.3640846, g: 0.34543964, b: 0.05763617, a: 1}
PrimaryColor: {r: 0.14775725, g: 0.07352568, b: 0.7352567, a: 1}
TrimColor: {r: 0.06331455, g: 0.03786368, b: 0.26474333, a: 1}
engine: {fileID: 1710334234404381546}
cam: {fileID: 2365855355768168390}
--- !u!114 &114571606569623246
MonoBehaviour:

m_Name:
m_EditorClassIdentifier:
_buoyancyType: 3
density: 405.62808
volume: 7.889
voxelResolution: 0.5
centerOfMass: {x: 0, y: -0.35, z: -0.8}
density: 483.749
volume: 6.6150007
voxelResolution: 0.3
centerOfMass: {x: 0, y: -0.25, z: -0.55}
- {x: -0.6999999, y: -0.019224256, z: -2.3381913}
- {x: -0.6999999, y: -0.019224256, z: -1.6381911}
- {x: -0.6999999, y: -0.019224256, z: -0.93819106}
- {x: -0.6999999, y: -0.019224256, z: -0.2381911}
- {x: -0.6999999, y: -0.019224256, z: 0.46180892}
- {x: 0.000000029802322, y: -0.019224256, z: -3.0381913}
- {x: 0.000000029802322, y: -0.019224256, z: -2.3381913}
- {x: 0.000000029802322, y: -0.019224256, z: -1.6381911}
- {x: 0.000000029802322, y: -0.019224256, z: -0.93819106}
- {x: 0.000000029802322, y: -0.019224256, z: -0.2381911}
- {x: 0.000000029802322, y: -0.019224256, z: 0.46180892}
- {x: 0.000000029802322, y: -0.019224256, z: 1.1618088}
- {x: 0.000000029802322, y: -0.019224256, z: 1.8618088}
- {x: 0.000000029802322, y: 0.68077576, z: -2.3381913}
- {x: 0.000000029802322, y: 0.68077576, z: -1.6381911}
- {x: 0.000000029802322, y: 0.68077576, z: -0.93819106}
- {x: 0.000000029802322, y: 0.68077576, z: -0.2381911}
- {x: 0.000000029802322, y: 0.68077576, z: 0.46180892}
- {x: 0.70000005, y: -0.019224256, z: -2.3381913}
- {x: 0.70000005, y: -0.019224256, z: -1.6381911}
- {x: 0.70000005, y: -0.019224256, z: -0.93819106}
- {x: 0.70000005, y: -0.019224256, z: -0.2381911}
- {x: 0.70000005, y: -0.019224256, z: 0.46180892}
- {x: -0.9000001, y: 0.18077567, z: -2.0381937}
- {x: -0.9000001, y: 0.18077567, z: -1.7381939}
- {x: -0.9000001, y: 0.18077567, z: -1.4381939}
- {x: -0.9000001, y: 0.18077567, z: -1.138194}
- {x: -0.9000001, y: 0.18077567, z: -0.8381939}
- {x: -0.9000001, y: 0.18077567, z: -0.53819394}
- {x: -0.9000001, y: 0.18077567, z: -0.2381939}
- {x: -0.9000001, y: 0.18077567, z: 0.061806113}
- {x: -0.6, y: -0.11922434, z: -1.4381939}
- {x: -0.6, y: -0.11922434, z: -1.138194}
- {x: -0.6, y: -0.11922434, z: -0.8381939}
- {x: -0.6, y: -0.11922434, z: -0.53819394}
- {x: -0.6, y: -0.11922434, z: -0.2381939}
- {x: -0.6, y: -0.11922434, z: 0.061806113}
- {x: -0.6, y: 0.18077567, z: -2.9381936}
- {x: -0.6, y: 0.18077567, z: -2.6381936}
- {x: -0.6, y: 0.18077567, z: -2.3381937}
- {x: -0.6, y: 0.18077567, z: -2.0381937}
- {x: -0.6, y: 0.18077567, z: -1.7381939}
- {x: -0.6, y: 0.18077567, z: -1.4381939}
- {x: -0.6, y: 0.18077567, z: -1.138194}
- {x: -0.6, y: 0.18077567, z: -0.8381939}
- {x: -0.6, y: 0.18077567, z: -0.53819394}
- {x: -0.6, y: 0.18077567, z: -0.2381939}
- {x: -0.6, y: 0.18077567, z: 0.061806113}
- {x: -0.6, y: 0.18077567, z: 0.36180615}
- {x: -0.6, y: 0.18077567, z: 0.6618061}
- {x: -0.6, y: 0.18077567, z: 0.9618062}
- {x: -0.6, y: 0.18077567, z: 1.2618061}
- {x: -0.6, y: 0.48077568, z: -2.6381936}
- {x: -0.6, y: 0.48077568, z: -2.3381937}
- {x: -0.6, y: 0.48077568, z: -2.0381937}
- {x: -0.6, y: 0.48077568, z: -1.7381939}
- {x: -0.6, y: 0.48077568, z: -1.4381939}
- {x: -0.6, y: 0.48077568, z: -1.138194}
- {x: -0.6, y: 0.48077568, z: -0.8381939}
- {x: -0.6, y: 0.48077568, z: -0.53819394}
- {x: -0.6, y: 0.48077568, z: -0.2381939}
- {x: -0.6, y: 0.48077568, z: 0.061806113}
- {x: -0.6, y: 0.48077568, z: 0.36180615}
- {x: -0.6, y: 0.48077568, z: 0.6618061}
- {x: -0.30000004, y: -0.11922434, z: -2.6381936}
- {x: -0.30000004, y: -0.11922434, z: -2.3381937}
- {x: -0.30000004, y: -0.11922434, z: -2.0381937}
- {x: -0.30000004, y: -0.11922434, z: -1.7381939}
- {x: -0.30000004, y: -0.11922434, z: -1.4381939}
- {x: -0.30000004, y: -0.11922434, z: -1.138194}
- {x: -0.30000004, y: -0.11922434, z: -0.8381939}
- {x: -0.30000004, y: -0.11922434, z: -0.53819394}
- {x: -0.30000004, y: -0.11922434, z: -0.2381939}
- {x: -0.30000004, y: -0.11922434, z: 0.061806113}
- {x: -0.30000004, y: -0.11922434, z: 0.36180615}
- {x: -0.30000004, y: -0.11922434, z: 0.6618061}
- {x: -0.30000004, y: -0.11922434, z: 0.9618062}
- {x: -0.30000004, y: 0.18077567, z: -2.9381936}
- {x: -0.30000004, y: 0.18077567, z: -2.6381936}
- {x: -0.30000004, y: 0.18077567, z: -2.3381937}
- {x: -0.30000004, y: 0.18077567, z: -2.0381937}
- {x: -0.30000004, y: 0.18077567, z: -1.7381939}
- {x: -0.30000004, y: 0.18077567, z: -1.4381939}
- {x: -0.30000004, y: 0.18077567, z: -1.138194}
- {x: -0.30000004, y: 0.18077567, z: -0.8381939}
- {x: -0.30000004, y: 0.18077567, z: -0.53819394}
- {x: -0.30000004, y: 0.18077567, z: -0.2381939}
- {x: -0.30000004, y: 0.18077567, z: 0.061806113}
- {x: -0.30000004, y: 0.18077567, z: 0.36180615}
- {x: -0.30000004, y: 0.18077567, z: 0.6618061}
- {x: -0.30000004, y: 0.18077567, z: 0.9618062}
- {x: -0.30000004, y: 0.18077567, z: 1.2618061}
- {x: -0.30000004, y: 0.18077567, z: 1.5618061}
- {x: -0.30000004, y: 0.18077567, z: 1.8618062}
- {x: -0.30000004, y: 0.48077568, z: -2.9381936}
- {x: -0.30000004, y: 0.48077568, z: -2.6381936}
- {x: -0.30000004, y: 0.48077568, z: -2.3381937}
- {x: -0.30000004, y: 0.48077568, z: -2.0381937}
- {x: -0.30000004, y: 0.48077568, z: -1.7381939}
- {x: -0.30000004, y: 0.48077568, z: -1.4381939}
- {x: -0.30000004, y: 0.48077568, z: -1.138194}
- {x: -0.30000004, y: 0.48077568, z: -0.8381939}
- {x: -0.30000004, y: 0.48077568, z: -0.53819394}
- {x: -0.30000004, y: 0.48077568, z: -0.2381939}
- {x: -0.30000004, y: 0.48077568, z: 0.061806113}
- {x: -0.30000004, y: 0.48077568, z: 0.36180615}
- {x: -0.30000004, y: 0.48077568, z: 0.6618061}
- {x: -0.30000004, y: 0.48077568, z: 0.9618062}
- {x: -0.30000004, y: 0.48077568, z: 1.2618061}
- {x: -0.30000004, y: 0.48077568, z: 1.5618061}
- {x: -0.30000004, y: 0.78077567, z: -2.3381937}
- {x: -0.30000004, y: 0.78077567, z: -2.0381937}
- {x: -0.30000004, y: 0.78077567, z: -1.7381939}
- {x: -0.30000004, y: 0.78077567, z: -1.4381939}
- {x: -0.30000004, y: 0.78077567, z: -1.138194}
- {x: -0.30000004, y: 0.78077567, z: -0.8381939}
- {x: -0.000000029802322, y: -0.11922434, z: -2.9381936}
- {x: -0.000000029802322, y: -0.11922434, z: -2.6381936}
- {x: -0.000000029802322, y: -0.11922434, z: -2.3381937}
- {x: -0.000000029802322, y: -0.11922434, z: -2.0381937}
- {x: -0.000000029802322, y: -0.11922434, z: -1.7381939}
- {x: -0.000000029802322, y: -0.11922434, z: -1.4381939}
- {x: -0.000000029802322, y: -0.11922434, z: -1.138194}
- {x: -0.000000029802322, y: -0.11922434, z: -0.8381939}
- {x: -0.000000029802322, y: -0.11922434, z: -0.53819394}
- {x: -0.000000029802322, y: -0.11922434, z: -0.2381939}
- {x: -0.000000029802322, y: -0.11922434, z: 0.061806113}
- {x: -0.000000029802322, y: -0.11922434, z: 0.36180615}
- {x: -0.000000029802322, y: -0.11922434, z: 0.6618061}
- {x: -0.000000029802322, y: -0.11922434, z: 0.9618062}
- {x: -0.000000029802322, y: -0.11922434, z: 1.2618061}
- {x: -0.000000029802322, y: 0.18077567, z: -2.9381936}
- {x: -0.000000029802322, y: 0.18077567, z: -2.6381936}
- {x: -0.000000029802322, y: 0.18077567, z: -2.3381937}
- {x: -0.000000029802322, y: 0.18077567, z: -2.0381937}
- {x: -0.000000029802322, y: 0.18077567, z: -1.7381939}
- {x: -0.000000029802322, y: 0.18077567, z: -1.4381939}
- {x: -0.000000029802322, y: 0.18077567, z: -1.138194}
- {x: -0.000000029802322, y: 0.18077567, z: -0.8381939}
- {x: -0.000000029802322, y: 0.18077567, z: -0.53819394}
- {x: -0.000000029802322, y: 0.18077567, z: -0.2381939}
- {x: -0.000000029802322, y: 0.18077567, z: 0.061806113}
- {x: -0.000000029802322, y: 0.18077567, z: 0.36180615}
- {x: -0.000000029802322, y: 0.18077567, z: 0.6618061}
- {x: -0.000000029802322, y: 0.18077567, z: 0.9618062}
- {x: -0.000000029802322, y: 0.18077567, z: 1.2618061}
- {x: -0.000000029802322, y: 0.18077567, z: 1.5618061}
- {x: -0.000000029802322, y: 0.18077567, z: 1.8618062}
- {x: -0.000000029802322, y: 0.18077567, z: 2.161806}
- {x: -0.000000029802322, y: 0.48077568, z: -2.9381936}
- {x: -0.000000029802322, y: 0.48077568, z: -2.6381936}
- {x: -0.000000029802322, y: 0.48077568, z: -2.3381937}
- {x: -0.000000029802322, y: 0.48077568, z: -2.0381937}
- {x: -0.000000029802322, y: 0.48077568, z: -1.7381939}
- {x: -0.000000029802322, y: 0.48077568, z: -1.4381939}
- {x: -0.000000029802322, y: 0.48077568, z: -1.138194}
- {x: -0.000000029802322, y: 0.48077568, z: -0.8381939}
- {x: -0.000000029802322, y: 0.48077568, z: -0.53819394}
- {x: -0.000000029802322, y: 0.48077568, z: -0.2381939}
- {x: -0.000000029802322, y: 0.48077568, z: 0.061806113}
- {x: -0.000000029802322, y: 0.48077568, z: 0.36180615}
- {x: -0.000000029802322, y: 0.48077568, z: 0.6618061}
- {x: -0.000000029802322, y: 0.48077568, z: 0.9618062}
- {x: -0.000000029802322, y: 0.48077568, z: 1.2618061}
- {x: -0.000000029802322, y: 0.48077568, z: 1.5618061}
- {x: -0.000000029802322, y: 0.48077568, z: 1.8618062}
- {x: -0.000000029802322, y: 0.48077568, z: 2.161806}
- {x: -0.000000029802322, y: 0.78077567, z: -2.3381937}
- {x: -0.000000029802322, y: 0.78077567, z: -2.0381937}
- {x: -0.000000029802322, y: 0.78077567, z: -1.7381939}
- {x: -0.000000029802322, y: 0.78077567, z: -1.4381939}
- {x: -0.000000029802322, y: 0.78077567, z: -1.138194}
- {x: -0.000000029802322, y: 0.78077567, z: -0.8381939}
- {x: -0.000000029802322, y: 0.78077567, z: -0.53819394}
- {x: -0.000000029802322, y: 0.78077567, z: -0.2381939}
- {x: 0.29999998, y: -0.11922434, z: -2.6381936}
- {x: 0.29999998, y: -0.11922434, z: -2.3381937}
- {x: 0.29999998, y: -0.11922434, z: -2.0381937}
- {x: 0.29999998, y: -0.11922434, z: -1.7381939}
- {x: 0.29999998, y: -0.11922434, z: -1.4381939}
- {x: 0.29999998, y: -0.11922434, z: -1.138194}
- {x: 0.29999998, y: -0.11922434, z: -0.8381939}
- {x: 0.29999998, y: -0.11922434, z: -0.53819394}
- {x: 0.29999998, y: -0.11922434, z: -0.2381939}
- {x: 0.29999998, y: -0.11922434, z: 0.061806113}
- {x: 0.29999998, y: -0.11922434, z: 0.36180615}
- {x: 0.29999998, y: -0.11922434, z: 0.6618061}
- {x: 0.29999998, y: -0.11922434, z: 0.9618062}
- {x: 0.29999998, y: 0.18077567, z: -2.9381936}
- {x: 0.29999998, y: 0.18077567, z: -2.6381936}
- {x: 0.29999998, y: 0.18077567, z: -2.3381937}
- {x: 0.29999998, y: 0.18077567, z: -2.0381937}
- {x: 0.29999998, y: 0.18077567, z: -1.7381939}
- {x: 0.29999998, y: 0.18077567, z: -1.4381939}
- {x: 0.29999998, y: 0.18077567, z: -1.138194}
- {x: 0.29999998, y: 0.18077567, z: -0.8381939}
- {x: 0.29999998, y: 0.18077567, z: -0.53819394}
- {x: 0.29999998, y: 0.18077567, z: -0.2381939}
- {x: 0.29999998, y: 0.18077567, z: 0.061806113}
- {x: 0.29999998, y: 0.18077567, z: 0.36180615}
- {x: 0.29999998, y: 0.18077567, z: 0.6618061}
- {x: 0.29999998, y: 0.18077567, z: 0.9618062}
- {x: 0.29999998, y: 0.18077567, z: 1.2618061}
- {x: 0.29999998, y: 0.18077567, z: 1.5618061}
- {x: 0.29999998, y: 0.18077567, z: 1.8618062}
- {x: 0.29999998, y: 0.48077568, z: -2.9381936}
- {x: 0.29999998, y: 0.48077568, z: -2.6381936}
- {x: 0.29999998, y: 0.48077568, z: -2.3381937}
- {x: 0.29999998, y: 0.48077568, z: -2.0381937}
- {x: 0.29999998, y: 0.48077568, z: -1.7381939}
- {x: 0.29999998, y: 0.48077568, z: -1.4381939}
- {x: 0.29999998, y: 0.48077568, z: -1.138194}
- {x: 0.29999998, y: 0.48077568, z: -0.8381939}
- {x: 0.29999998, y: 0.48077568, z: -0.53819394}
- {x: 0.29999998, y: 0.48077568, z: -0.2381939}
- {x: 0.29999998, y: 0.48077568, z: 0.061806113}
- {x: 0.29999998, y: 0.48077568, z: 0.36180615}
- {x: 0.29999998, y: 0.48077568, z: 0.6618061}
- {x: 0.29999998, y: 0.48077568, z: 0.9618062}
- {x: 0.29999998, y: 0.48077568, z: 1.2618061}
- {x: 0.29999998, y: 0.48077568, z: 1.5618061}
- {x: 0.29999998, y: 0.78077567, z: -2.3381937}
- {x: 0.29999998, y: 0.78077567, z: -2.0381937}
- {x: 0.29999998, y: 0.78077567, z: -1.7381939}
- {x: 0.29999998, y: 0.78077567, z: -1.4381939}
- {x: 0.29999998, y: 0.78077567, z: -1.138194}
- {x: 0.29999998, y: 0.78077567, z: -0.8381939}
- {x: 0.6, y: -0.11922434, z: -1.4381939}
- {x: 0.6, y: -0.11922434, z: -1.138194}
- {x: 0.6, y: -0.11922434, z: -0.8381939}
- {x: 0.6, y: -0.11922434, z: -0.53819394}
- {x: 0.6, y: -0.11922434, z: -0.2381939}
- {x: 0.6, y: -0.11922434, z: 0.061806113}
- {x: 0.6, y: 0.18077567, z: -2.9381936}
- {x: 0.6, y: 0.18077567, z: -2.6381936}
- {x: 0.6, y: 0.18077567, z: -2.3381937}
- {x: 0.6, y: 0.18077567, z: -2.0381937}
- {x: 0.6, y: 0.18077567, z: -1.7381939}
- {x: 0.6, y: 0.18077567, z: -1.4381939}
- {x: 0.6, y: 0.18077567, z: -1.138194}
- {x: 0.6, y: 0.18077567, z: -0.8381939}
- {x: 0.6, y: 0.18077567, z: -0.53819394}
- {x: 0.6, y: 0.18077567, z: -0.2381939}
- {x: 0.6, y: 0.18077567, z: 0.061806113}
- {x: 0.6, y: 0.18077567, z: 0.36180615}
- {x: 0.6, y: 0.18077567, z: 0.6618061}
- {x: 0.6, y: 0.18077567, z: 0.9618062}
- {x: 0.6, y: 0.18077567, z: 1.2618061}
- {x: 0.6, y: 0.48077568, z: -2.6381936}
- {x: 0.6, y: 0.48077568, z: -2.3381937}
- {x: 0.6, y: 0.48077568, z: -2.0381937}
- {x: 0.6, y: 0.48077568, z: -1.7381939}
- {x: 0.6, y: 0.48077568, z: -1.4381939}
- {x: 0.6, y: 0.48077568, z: -1.138194}
- {x: 0.6, y: 0.48077568, z: -0.8381939}
- {x: 0.6, y: 0.48077568, z: -0.53819394}
- {x: 0.6, y: 0.48077568, z: -0.2381939}
- {x: 0.6, y: 0.48077568, z: 0.061806113}
- {x: 0.6, y: 0.48077568, z: 0.36180615}
- {x: 0.6, y: 0.48077568, z: 0.6618061}
- {x: 0.9, y: 0.18077567, z: -2.0381937}
- {x: 0.9, y: 0.18077567, z: -1.7381939}
- {x: 0.9, y: 0.18077567, z: -1.4381939}
- {x: 0.9, y: 0.18077567, z: -1.138194}
- {x: 0.9, y: 0.18077567, z: -0.8381939}
- {x: 0.9, y: 0.18077567, z: -0.53819394}
- {x: 0.9, y: 0.18077567, z: -0.2381939}
- {x: 0.9, y: 0.18077567, z: 0.061806113}
--- !u!114 &1169622266
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1553288845585282}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c46922a8ed04b0081de10e51b3762f, type: 3}
m_Name:
m_EditorClassIdentifier:
vel: {x: 0, y: 0, z: 0}
engineSound: {fileID: 82633756123786494}
waterSound: {fileID: 82912682702107868}
torque: 5
horsePower: 18
enginePosition: {x: 0, y: 0.05, z: -3.31}
--- !u!1 &1610670695541802
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 1857749394586354482}
- component: {fileID: 1036935742331195195}
- component: {fileID: 3607957023957793550}
- component: {fileID: 1710334234404381546}
m_Layer: 0
m_Name: Engine
m_TagString: Untagged

m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.064, z: -3.3079998}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4653116848354930}
m_Children: []
m_Father: {fileID: 4566539937980892}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &1710334234404381546
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5982248302829913771}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c46922a8ed04b0081de10e51b3762f, type: 3}
m_Name:
m_EditorClassIdentifier:
RB: {fileID: 54710712322113256}
vel: 0
engineSound: {fileID: 82633756123786494}
waterSound: {fileID: 82912682702107868}
horsePower: 10
turnAngle: 45
enginePosition: {x: 0, y: 0, z: -0.12}
--- !u!1 &8128372730392016786
GameObject:
m_ObjectHideFlags: 0

7
Assets/Scripts/Boat/BoatController.cs


public Color PrimaryColor; // Boat primary colour
public Color TrimColor; // Boat secondary colour
public Renderer boatRenderer; // The renderer for the boat mesh
public Engine engine;
public CinemachineVirtualCamera cam;
void OnValidate()

Colourize();
if (Human)
{
gameObject.AddComponent<HumanController>().engine = engine; // Adds a human controller if human
gameObject.AddComponent<HumanController>(); // Adds a human controller if human
gameObject.AddComponent<AIcontroller>().engine = engine; // Adds an AI controller if AI
gameObject.AddComponent<AIcontroller>(); // Adds an AI controller if AI
}
}

107
Assets/Scripts/Boat/Engine.cs


using System.Collections;
using WaterSystem;
using Unity.Mathematics;
using Unity.Entities;
public class Engine : MonoBehaviour
{
public Rigidbody RB; // The rigid body attatched to the boat
public float vel; // Boats velocity
public class Engine : MonoBehaviour, IConvertGameObjectToEntity
{
private Rigidbody RB; // The rigid body attatched to the boat
public Vector3 vel; // Boats velocity
public AudioSource engineSound; // Engine sound clip
public AudioSource waterSound; // Water sound clip
public AudioSource engineSound; // Engine sound clip
public AudioSource waterSound; // Water sound clip
private float turnVel = 0f;
//engine stats
public float horsePower = 15f;
public float turnAngle = 45f;
private float3[] point = new float3[1]; // engine submerged check
private float3[] heights = new float3[1]; // engine submerged check
private int _guid;
private float yHeight;
//engine stats
public float torque = 5f;
public float horsePower = 15f;
private float3[] point = new float3[1]; // engine submerged check
private float3[] heights = new float3[1]; // engine submerged check
private int _guid;
private float yHeight;
public Vector3 enginePosition;
private Vector3 engineDir;
public Vector3 enginePosition;
private Vector3 engineDir;
void Awake()
void Awake()
engineSound.time = UnityEngine.Random.Range(0f, engineSound.clip.length); // randomly start the engine sound
waterSound.time = UnityEngine.Random.Range(0f, waterSound.clip.length); // randomly start the water sound
RB = gameObject.GetComponent<Rigidbody>(); // get the RB
engineSound.time = UnityEngine.Random.Range(0f, engineSound.clip.length); // randomly start the engine sound
waterSound.time = UnityEngine.Random.Range(0f, waterSound.clip.length); // randomly start the water sound
_guid = this.GetInstanceID(); // Get the engines GUID for the buoyancy system
}
_guid = this.GetInstanceID(); // Get the engines GUID for the buoyancy system
}
vel = RB.velocity.sqrMagnitude; // get the sqr mag
engineSound.pitch = Mathf.Max(vel * 0.01f, 0.3f); // use some magice numbers to control the pitch of the engine sound
vel = RB.velocity; // store the velocity
float velMag = vel.sqrMagnitude; // get the sqr mag
engineSound.pitch = Mathf.Max(velMag * 0.01f, 0.3f); // use some magice numbers to control the pitch of the engine sound
// Get the water level from the engines position and store it
point[0] = transform.TransformPoint(enginePosition);
GerstnerWavesJobs.UpdateSamplePoints(point, _guid, false);
GerstnerWavesJobs.GetData(_guid, ref heights);
yHeight = heights[0].y - point[0].y;
}
// Get the water level from the engines position and store it
point[0] = transform.TransformPoint(enginePosition);
GerstnerWavesJobs.UpdateSamplePoints(point, _guid, false);
GerstnerWavesJobs.GetData(_guid, ref heights);
yHeight = heights[0].y - point[0].y;
}
/// <summary>
/// Controls the acceleration of the boat

{
if (yHeight > -0.2f) // if the engine is deeper than 0.1
{
Vector3 forward = Vector3.Slerp(RB.transform.forward, transform.forward, 0.2f);
//forward.y = 0f;
//forward.Normalize();
RB.AddForceAtPosition(forward * modifier * horsePower, point[0], ForceMode.Acceleration); // add force forward based on input and horsepower
RB.AddRelativeTorque(-Vector3.right * modifier, ForceMode.Acceleration);
}
}
if (yHeight > -0.1f) // if the engine is deeper than 0.1
{
modifier = Mathf.Clamp(modifier, 0f, 1f); // clamp for reasonable values
Vector3 forward = transform.forward;
forward.y = 0f;
forward.Normalize();
RB.AddForce(forward * modifier * horsePower, ForceMode.Acceleration); // add force forward based on input and horsepower
RB.AddRelativeTorque(-Vector3.right * modifier, ForceMode.Acceleration);
}
}
/// <summary>
/// Controls the turning of the boat

{
var curAngle = transform.localEulerAngles.y;
var angle = Mathf.SmoothDampAngle(curAngle, -modifier * turnAngle, ref turnVel, 0.2f);
transform.localEulerAngles = new Vector3(0f, angle, 0f);
//RB.AddRelativeTorque(vel * -0.001f * new Vector3(0f, angle > 180 ? angle - 360 : angle, 0f), ForceMode.Acceleration); // add torque based on input and torque amount
}
if (yHeight > -0.1f) // if the engine is deeper than 0.1
{
modifier = Mathf.Clamp(modifier, -1f, 1f); // clamp for reasonable values
RB.AddRelativeTorque(new Vector3(0f, torque, -torque * 0.5f) * modifier, ForceMode.Acceleration); // add torque based on input and torque amount
}
}
// Draw some helper gizmos
void OnDrawGizmosSelected()

Gizmos.DrawCube(enginePosition, new Vector3(0.1f, 0.2f, 0.3f)); // Draw teh engine position with sphere
}
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = new DrivingData {
torque = torque,
horsePower = horsePower,
engineOffset = transform.TransformPoint(enginePosition) - transform.position
};
dstManager.AddComponentData(entity, data);
}
}
}

4
Assets/Scripts/Boat/HumanController.cs


controls.BoatControls.Steering.performed += context => steering = context.ReadValue<float>();
controls.BoatControls.Steering.canceled += context => steering = 0f;
}
engine = GetComponent<Engine>(); // get the engine script
}
private void OnEnable()
{

11
Assets/Unity Physics Items/ApplyBuoyancyForceSystem.cs


protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Debug.Log(string.Format("DeltaTime: {0}, Time.time {1}, Calc Delta: {2}", Time.deltaTime, Time.time, Time.time - lastTime));
lastTime = Time.time;
//Debug.Log(string.Format("DeltaTime: {0}, Time.time {1}, Calc Delta: {2}", Time.deltaTime, Time.time, Time.time - lastTime));
//lastTime = Time.time;
var job = new ForceJob()
{
dt = Time.deltaTime,

velocity.y *= 2f;
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);
//entity.ApplyImpulse(force, wp);//RB.AddForceAtPosition(force, 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));
ComponentExtensions.ApplyImpulse(ref vel, mass, pos, rot, force * dt * mass.InverseMass, 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));
}
}

4
Assets/Unity Physics Items/BuoyantObject2.cs


namespace WaterSystem
{
public class BuoyantObject2 : MonoBehaviour//, IConvertGameObjectToEntity
public class BuoyantObject2 : MonoBehaviour, IConvertGameObjectToEntity
{
public BuoyancyType _buoyancyType; // type of buoyancy to calculate
public float density; // density of the object, this is calculated off it's volume and mass

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

39
Assets/Unity Physics Items/Physics Scene.unity


m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &180195172
MonoBehaviour:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
- target: {fileID: 400000, guid: 074aa8ca109924e18baf19f3e26665b6, type: 3}
propertyPath: m_LocalPosition.x
value: -93.75
value: -100
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: 074aa8ca109924e18baf19f3e26665b6, type: 3}
propertyPath: m_LocalPosition.y

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &1501079343
MonoBehaviour:
m_ObjectHideFlags: 0

colliders:
- {fileID: 1531988075}
percentSubmerged: 0
--- !u!114 &1531988078
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1531988074}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c46922a8ed04b0081de10e51b3762f, type: 3}
m_Name:
m_EditorClassIdentifier:
vel: {x: 0, y: 0, z: 0}
engineSound: {fileID: 3457973741408294004}
waterSound: {fileID: 3457973741408294003}
torque: 5
horsePower: 18
enginePosition: {x: 0, y: 0.05, z: -3.31}
--- !u!1 &1591128532
GameObject:
m_ObjectHideFlags: 3

- target: {fileID: 3457973740146875416, guid: 0a308b87c1579fb4c9ea256406209ca5,
type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3457973740146875417, guid: 0a308b87c1579fb4c9ea256406209ca5,
type: 3}

- {fileID: 3344550060052829039, guid: 0a308b87c1579fb4c9ea256406209ca5, type: 3}
- {fileID: 1531988078, guid: 0a308b87c1579fb4c9ea256406209ca5, type: 3}
- {fileID: 1531988076, guid: 0a308b87c1579fb4c9ea256406209ca5, type: 3}
- {fileID: 3457973739838196059, guid: 0a308b87c1579fb4c9ea256406209ca5, type: 3}
--- !u!82 &3457973741408294003 stripped
AudioSource:
m_CorrespondingSourceObject: {fileID: 3376468742497974653, guid: 0a308b87c1579fb4c9ea256406209ca5,
type: 3}
m_PrefabInstance: {fileID: 3457973741408294002}
m_PrefabAsset: {fileID: 0}
--- !u!82 &3457973741408294004 stripped
AudioSource:
m_CorrespondingSourceObject: {fileID: 3375626305472995679, guid: 0a308b87c1579fb4c9ea256406209ca5,
type: 3}
m_PrefabInstance: {fileID: 3457973741408294002}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &6543823577887040592
PrefabInstance:
m_ObjectHideFlags: 0

2
Assets/Unity Physics Items/PhysicsConversionSystem.cs


// Update is called once per frame
protected override void OnUpdate()
{
Entities.ForEach((BuoyantObject2 behaviour) => { behaviour.Convert(GetPrimaryEntity(behaviour), DstEntityManager, this); });
//Entities.ForEach((BuoyantObject2 behaviour) => { behaviour.Convert(GetPrimaryEntity(behaviour), DstEntityManager, this); });
}
}
}

18
Assets/Unity Physics Items/BoatDriveSystem.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoatDriveSystem : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

11
Assets/Unity Physics Items/BoatDriveSystem.cs.meta


fileFormatVersion: 2
guid: 1c6f1509c9123b744893eac97a7388fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

88
Assets/Unity Physics Items/DriveSystem.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Physics.Extensions;
using Unity.Transforms;
using UnityEngine;
[UpdateAfter(typeof(ApplyBuoyancyForceSystem))]
public class DriveSystem : JobComponentSystem
{
InputControls controls;
float throttle;
float steering;
protected override void OnCreate()
{
controls = new InputControls();
controls.BoatControls.Trottle.performed += context => throttle = context.ReadValue<float>();
controls.BoatControls.Trottle.canceled += context => throttle = 0f;
controls.BoatControls.Steering.performed += context => steering = context.ReadValue<float>();
controls.BoatControls.Steering.canceled += context => steering = 0f;
controls.BoatControls.Enable();
base.OnCreate();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new DriveWithInputJob()
{
dt = Time.deltaTime,
throttle = throttle,
steering = steering
};
return job.Schedule(this, inputDeps);
}
[RequireComponentTag(typeof(MoveWithInputTag))]
public struct DriveWithInputJob : IJobForEachWithEntity<Translation, Rotation, PhysicsVelocity, PhysicsMass, DrivingData>
{
public float dt;
public float throttle;
public float steering;
public void Execute(Entity entity, int index, ref Translation pos, ref Rotation rot, ref PhysicsVelocity vel, ref PhysicsMass mass, ref DrivingData data)
{
Debug.Log(string.Format("Throttle: {0}, Steering {1}", throttle, steering));
float velMag = math.dot(vel.Linear, vel.Linear);
var wp = pos.Value + data.engineOffset;
if (wp.y <= -0.1f) // if the engine is deeper than 0.1
{
//accel
throttle = Mathf.Clamp(throttle, 0f, 1f); // clamp for reasonable values
float3 forward = math.forward(rot.Value);
forward.y = 0f;
forward = math.normalize(forward);
var force = (forward * throttle * data.horsePower) / mass.InverseMass; //divide by iMass to counteract mass in impulse method
var torque = (throttle * new float3(-1, 0, 0)) / mass.InverseInertia;
ComponentExtensions.ApplyLinearImpulse(ref vel, mass, force * dt);
ComponentExtensions.ApplyAngularImpulse(ref vel, mass, torque * dt);
//RB.AddForce(forward * modifier * horsePower, ForceMode.Acceleration); // add force forward based on input and horsepower
//RB.AddRelativeTorque(-Vector3.right * modifier, ForceMode.Acceleration);
//Turning
steering = Mathf.Clamp(steering, -1f, 1f); // clamp for reasonable values
var sTorque = new float3(0f, data.torque, -data.torque * .5f) * steering / mass.InverseInertia;
ComponentExtensions.ApplyAngularImpulse(ref vel, mass, sTorque * dt);
//RB.AddRelativeTorque(new Vector3(0f, torque, -torque * 0.5f) * modifier, ForceMode.Acceleration); // add torque based on input and torque amount
}
}
}
}

11
Assets/Unity Physics Items/DriveSystem.cs.meta


fileFormatVersion: 2
guid: 0bb75e9b16d3ccf46b42eb1f80cc44b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/Unity Physics Items/DrivingData.cs


using Unity.Entities;
using Unity.Mathematics;
public struct DrivingData : IComponentData
{
public float torque;
public float horsePower;
public float3 engineOffset;
}

11
Assets/Unity Physics Items/DrivingData.cs.meta


fileFormatVersion: 2
guid: eecb437b456d8484fb05784f0109d7b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

4
Assets/Unity Physics Items/MoveWithInputTag.cs


using Unity.Entities;
public struct MoveWithInputTag : IComponentData
{}

11
Assets/Unity Physics Items/MoveWithInputTag.cs.meta


fileFormatVersion: 2
guid: 6de2728723685584083eab3960a2daac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存