浏览代码

-optimizaed AI System further and removed all DOTS AI system

-Added nose pitch to drive system
-Split drive data from input data
-Still getting jerky performance
/dots-physics
Mike Geig 5 年前
当前提交
3581ffda
共有 14 个文件被更改,包括 1364 次插入2354 次删除
  1. 27
      Assets/Scripts/Boat/Engine.cs
  2. 71
      Assets/Unity Physics Items/AIController_DOTS.cs
  3. 2
      Assets/Unity Physics Items/AIController_DOTS.cs.meta
  4. 3
      Assets/Unity Physics Items/BuoyantObject_DOTS.cs
  5. 11
      Assets/Unity Physics Items/Components/BoatDataComponents.cs
  6. 980
      Assets/Unity Physics Items/Junk.unity
  7. 951
      Assets/Unity Physics Items/Physics Scene.unity
  8. 980
      Assets/Unity Physics Items/Prefabs/AIBoatEntity Variant.prefab
  9. 514
      Assets/Unity Physics Items/Prefabs/BoatEntity.prefab
  10. 7
      Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs
  11. 29
      Assets/Unity Physics Items/Systems/DriveSystem.cs
  12. 6
      Assets/Unity Physics Items/Systems/InputSystem.cs
  13. 126
      Assets/Unity Physics Items/AIController_DOTS2.cs
  14. 11
      Assets/Unity Physics Items/AIController_DOTS2.cs.meta

27
Assets/Scripts/Boat/Engine.cs


public AudioSource waterSound; // Water sound clip
//engine stats
public float torque = 5f;
public float horsePower = 15f;
public float steeringTorque = 5f;
public float upwardTorque = 5f;
public float horsePower = 18f;
private float3[] point = new float3[1]; // engine submerged check
private float3[] heights = new float3[1]; // engine submerged check
private int _guid;

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
RB.AddRelativeTorque(new Vector3(0f, steeringTorque, -steeringTorque * 0.5f) * modifier, ForceMode.Acceleration); // add torque based on input and torque amount
}
}

bool isHuman = GetComponent<BoatController>().Human;
if (!isHuman)
AIController_DOTS2.Register(entity, transform.position);
//AIController_DOTS.Register(entity);
AIController_DOTS.Register(entity, transform.position);
var data = new DrivingData
var driveData = new DrivingData
isHuman = isHuman,
torque = torque,
steeringTorque = steeringTorque,
upwardTorque = upwardTorque,
engineOffset = transform.TransformPoint(enginePosition) - transform.position
engineOffset = enginePosition
};
dstManager.AddComponentData(entity, driveData);
var inputData = new InputData
{
isHuman = isHuman
dstManager.AddComponentData(entity, data);
dstManager.AddComponentData(entity, inputData);
}
}
}

71
Assets/Unity Physics Items/AIController_DOTS.cs


using UnityEngine;
using UnityEngine.AI;
public Vector3[] pathPoint;
public int curPoint;
public int curWP;
public Vector3[] pathPoints;
public int currentPathPoint;
public WaypointGroup.Waypoint currentWaypoint;
public bool nearEnd;
public Vector3 storedPosition;
};
public class AIController_DOTS : MonoBehaviour

public float nearDistanceSquared = 8f;
Dictionary<Entity, PathData> paths;

paths = new Dictionary<Entity, PathData>();
}
public static void Register(Entity entity)
private void Update()
{
foreach (var path in paths)
{
if (path.Value.nearEnd || !path.Value.foundPath)
CalculatePath(path.Value);
}
}
public static void Register(Entity entity, Vector3 pos)
data.currentWaypoint = WaypointGroup.instance.GetClosestWaypoint(pos);
data.storedPosition = pos;
data.nearEnd = true;
main.paths.Add(entity, data);
}

//Do we have data?
PathData data;
if (!paths.TryGetValue(entity, out data))
if (!paths.TryGetValue(entity, out data) || data.pathPoints == null)
if (data.pathPoint == null)
{
WaypointGroup.Waypoint wp = WaypointGroup.instance.GetClosestWaypoint(pos);
CalculatePath(WaypointGroup.instance.GetNextWaypoint(wp), data, pos);
}
else if (data.pathPoint.Length > data.curPoint && data.foundPath)
{
if ((Vector3.Distance(pos, data.pathPoint[data.curPoint])) < 8) // If we are close to the current point on the path get the next
{
data.curPoint++; // Move on to next point
if (data.curPoint >= data.pathPoint.Length)
CalculatePath(WaypointGroup.instance.GetWaypoint(data.curWP), data, pos);
}
}
data.storedPosition = pos; //Store position for navmesh calculations
if (data.pathPoint != null && data.pathPoint.Length > data.curPoint)
if (data.currentPathPoint < data.pathPoints.Length && data.foundPath)
Vector3 normDir = data.pathPoint[data.curPoint] - (Vector3)pos;
Vector3 normDir = data.pathPoints[data.currentPathPoint] - (Vector3)pos;
normDir = normDir.normalized;
var forward = math.forward(rot);

steering = Mathf.Clamp(targetSide, -1.0f, 1.0f);
throttle = dot > 0 ? 1f : 0.25f;
if (Vector3.Distance(pos, data.pathPoints[data.currentPathPoint]) < nearDistanceSquared) // If we are close to the current point on the path get the next
{
//Debug.Log($"Distance: {Vector3.Distance(pos, data.pathPoints[data.currentPathPoint])} SqrMag: {(data.storedPosition - data.pathPoints[data.currentPathPoint]).sqrMagnitude}");
data.currentPathPoint++; // Move on to next point
if (data.currentPathPoint >= data.pathPoints.Length)
data.nearEnd = true;
}
void CalculatePath(WaypointGroup.Waypoint wp, PathData data, float3 pos)
void CalculatePath(PathData data)
var wp = WaypointGroup.instance.GetNextWaypoint(data.currentWaypoint);
data.curWP++;
if (data.curWP >= WaypointGroup.instance.WPs.Count)
data.curWP = 0;
NavMesh.CalculatePath(pos, curWPPos, 255, navPath);
NavMesh.CalculatePath(data.storedPosition, curWPPos, 255, navPath);
data.pathPoint = navPath.corners;
data.curPoint = 1;
data.currentWaypoint = wp;
data.pathPoints = navPath.corners;
data.currentPathPoint = 1;
data.nearEnd = false;
}
else if (navPath == null || navPath.status == NavMeshPathStatus.PathInvalid) // if the path is bad, we havent found a path
{

2
Assets/Unity Physics Items/AIController_DOTS.cs.meta


fileFormatVersion: 2
guid: d535e331fdb3f734cb363f09fa881545
guid: efe040b9229edbe42a6641620a4da643
MonoImporter:
externalObjects: {}
serializedVersion: 2

3
Assets/Unity Physics Items/BuoyantObject_DOTS.cs


data.type = _buoyancyType;
data.voxelResolution = voxelResolution;
data.localArchimedesForce = localArchimedesForce;
data.percentSubmerged = 0f;
data.baseDrag = baseDrag;
data.baseAngularDrag = baseAngularDrag;
dstManager.AddComponentData(entity, data);

var engine = GetComponent<Engine>();
if (engine)
{
offsets.Add(new VoxelOffset { Value = new float3(engine.enginePosition) - mass.CenterOfMass });
offsets.Add(new VoxelOffset { Value = new float3(engine.enginePosition - centerOfMass) });
heights.Add(new VoxelHeight { Value = float3.zero });
}

11
Assets/Unity Physics Items/Components/BoatDataComponents.cs


public float voxelResolution;
public float3 normal;
public float3 localArchimedesForce;
public float percentSubmerged;
public float percentSubmerged;
}
public struct VoxelOffset : IBufferElementData

public struct DrivingData : IComponentData
{
public bool isHuman;
public float torque;
public float steeringTorque;
public float upwardTorque;
}
public struct InputData : IComponentData
{
public bool isHuman;
public float throttle;
public float steering;
}

980
Assets/Unity Physics Items/Junk.unity
文件差异内容过多而无法显示
查看文件

951
Assets/Unity Physics Items/Physics Scene.unity
文件差异内容过多而无法显示
查看文件

980
Assets/Unity Physics Items/Prefabs/AIBoatEntity Variant.prefab
文件差异内容过多而无法显示
查看文件

514
Assets/Unity Physics Items/Prefabs/BoatEntity.prefab


m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 320792261470743900}
m_LocalRotation: {x: 0.09853761, y: 0.0000000038789105, z: 0.0000000036334136, w: 0.9951334}
m_LocalRotation: {x: 0.09853762, y: 0.0000000055235976, z: -0.000000012976303, w: 0.9951334}
m_LocalPosition: {x: 0, y: 2, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

- component: {fileID: 3453465595108755947}
- component: {fileID: 2092507921}
- component: {fileID: 2092507922}
- component: {fileID: 1507960575}
m_Layer: 11
m_Name: _Boat
m_TagString: boat

m_Name:
m_EditorClassIdentifier:
ConversionMode: 1
--- !u!114 &1507960575
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3456711171255019043}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d7931266a1a8224ea5dfc21625ffde1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &3456818236728735511
GameObject:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3457973740146875416}
serializedVersion: 2
m_Mass: 6400
m_Mass: 3200
m_Drag: 0.1
m_AngularDrag: 0.2
m_UseGravity: 1

m_Name:
m_EditorClassIdentifier:
_buoyancyType: 3
density: 967.498
density: 483.749
centerOfMass: {x: 0, y: -0.25, z: -0.4}
centerOfMass: {x: 0, y: -0.25, z: -0.55}
- {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}
- {x: -0.9000001, y: 0.18077579, z: -2.0381937}
- {x: -0.9000001, y: 0.18077579, z: -1.7381936}
- {x: -0.9000001, y: 0.18077579, z: -1.4381937}
- {x: -0.9000001, y: 0.18077579, z: -1.1381937}
- {x: -0.9000001, y: 0.18077579, z: -0.83819366}
- {x: -0.9000001, y: 0.18077579, z: -0.5381937}
- {x: -0.9000001, y: 0.18077579, z: -0.23819366}
- {x: -0.9000001, y: 0.18077579, z: 0.06180635}
- {x: -0.6, y: -0.11922422, z: -1.4381937}
- {x: -0.6, y: -0.11922422, z: -1.1381937}
- {x: -0.6, y: -0.11922422, z: -0.83819366}
- {x: -0.6, y: -0.11922422, z: -0.5381937}
- {x: -0.6, y: -0.11922422, z: -0.23819366}
- {x: -0.6, y: -0.11922422, z: 0.06180635}
- {x: -0.6, y: 0.18077579, z: -2.9381933}
- {x: -0.6, y: 0.18077579, z: -2.6381934}
- {x: -0.6, y: 0.18077579, z: -2.3381934}
- {x: -0.6, y: 0.18077579, z: -2.0381937}
- {x: -0.6, y: 0.18077579, z: -1.7381936}
- {x: -0.6, y: 0.18077579, z: -1.4381937}
- {x: -0.6, y: 0.18077579, z: -1.1381937}
- {x: -0.6, y: 0.18077579, z: -0.83819366}
- {x: -0.6, y: 0.18077579, z: -0.5381937}
- {x: -0.6, y: 0.18077579, z: -0.23819366}
- {x: -0.6, y: 0.18077579, z: 0.06180635}
- {x: -0.6, y: 0.18077579, z: 0.3618064}
- {x: -0.6, y: 0.18077579, z: 0.66180634}
- {x: -0.6, y: 0.18077579, z: 0.9618064}
- {x: -0.6, y: 0.18077579, z: 1.2618064}
- {x: -0.6, y: 0.4807758, z: -2.6381934}
- {x: -0.6, y: 0.4807758, z: -2.3381934}
- {x: -0.6, y: 0.4807758, z: -2.0381937}
- {x: -0.6, y: 0.4807758, z: -1.7381936}
- {x: -0.6, y: 0.4807758, z: -1.4381937}
- {x: -0.6, y: 0.4807758, z: -1.1381937}
- {x: -0.6, y: 0.4807758, z: -0.83819366}
- {x: -0.6, y: 0.4807758, z: -0.5381937}
- {x: -0.6, y: 0.4807758, z: -0.23819366}
- {x: -0.6, y: 0.4807758, z: 0.06180635}
- {x: -0.6, y: 0.4807758, z: 0.3618064}
- {x: -0.6, y: 0.4807758, z: 0.66180634}
- {x: -0.30000004, y: -0.11922422, z: -2.6381934}
- {x: -0.30000004, y: -0.11922422, z: -2.3381934}
- {x: -0.30000004, y: -0.11922422, z: -2.0381937}
- {x: -0.30000004, y: -0.11922422, z: -1.7381936}
- {x: -0.30000004, y: -0.11922422, z: -1.4381937}
- {x: -0.30000004, y: -0.11922422, z: -1.1381937}
- {x: -0.30000004, y: -0.11922422, z: -0.83819366}
- {x: -0.30000004, y: -0.11922422, z: -0.5381937}
- {x: -0.30000004, y: -0.11922422, z: -0.23819366}
- {x: -0.30000004, y: -0.11922422, z: 0.06180635}
- {x: -0.30000004, y: -0.11922422, z: 0.3618064}
- {x: -0.30000004, y: -0.11922422, z: 0.66180634}
- {x: -0.30000004, y: -0.11922422, z: 0.9618064}
- {x: -0.30000004, y: 0.18077579, z: -2.9381933}
- {x: -0.30000004, y: 0.18077579, z: -2.6381934}
- {x: -0.30000004, y: 0.18077579, z: -2.3381934}
- {x: -0.30000004, y: 0.18077579, z: -2.0381937}
- {x: -0.30000004, y: 0.18077579, z: -1.7381936}
- {x: -0.30000004, y: 0.18077579, z: -1.4381937}
- {x: -0.30000004, y: 0.18077579, z: -1.1381937}
- {x: -0.30000004, y: 0.18077579, z: -0.83819366}
- {x: -0.30000004, y: 0.18077579, z: -0.5381937}
- {x: -0.30000004, y: 0.18077579, z: -0.23819366}
- {x: -0.30000004, y: 0.18077579, z: 0.06180635}
- {x: -0.30000004, y: 0.18077579, z: 0.3618064}
- {x: -0.30000004, y: 0.18077579, z: 0.66180634}
- {x: -0.30000004, y: 0.18077579, z: 0.9618064}
- {x: -0.30000004, y: 0.18077579, z: 1.2618064}
- {x: -0.30000004, y: 0.18077579, z: 1.5618063}
- {x: -0.30000004, y: 0.18077579, z: 1.8618064}
- {x: -0.30000004, y: 0.4807758, z: -2.9381933}
- {x: -0.30000004, y: 0.4807758, z: -2.6381934}
- {x: -0.30000004, y: 0.4807758, z: -2.3381934}
- {x: -0.30000004, y: 0.4807758, z: -2.0381937}
- {x: -0.30000004, y: 0.4807758, z: -1.7381936}
- {x: -0.30000004, y: 0.4807758, z: -1.4381937}
- {x: -0.30000004, y: 0.4807758, z: -1.1381937}
- {x: -0.30000004, y: 0.4807758, z: -0.83819366}
- {x: -0.30000004, y: 0.4807758, z: -0.5381937}
- {x: -0.30000004, y: 0.4807758, z: -0.23819366}
- {x: -0.30000004, y: 0.4807758, z: 0.06180635}
- {x: -0.30000004, y: 0.4807758, z: 0.3618064}
- {x: -0.30000004, y: 0.4807758, z: 0.66180634}
- {x: -0.30000004, y: 0.4807758, z: 0.9618064}
- {x: -0.30000004, y: 0.4807758, z: 1.2618064}
- {x: -0.30000004, y: 0.4807758, z: 1.5618063}
- {x: -0.30000004, y: 0.7807758, z: -2.3381934}
- {x: -0.30000004, y: 0.7807758, z: -2.0381937}
- {x: -0.30000004, y: 0.7807758, z: -1.7381936}
- {x: -0.30000004, y: 0.7807758, z: -1.4381937}
- {x: -0.30000004, y: 0.7807758, z: -1.1381937}
- {x: -0.30000004, y: 0.7807758, z: -0.83819366}
- {x: -0.000000029802322, y: -0.11922422, z: -2.9381933}
- {x: -0.000000029802322, y: -0.11922422, z: -2.6381934}
- {x: -0.000000029802322, y: -0.11922422, z: -2.3381934}
- {x: -0.000000029802322, y: -0.11922422, z: -2.0381937}
- {x: -0.000000029802322, y: -0.11922422, z: -1.7381936}
- {x: -0.000000029802322, y: -0.11922422, z: -1.4381937}
- {x: -0.000000029802322, y: -0.11922422, z: -1.1381937}
- {x: -0.000000029802322, y: -0.11922422, z: -0.83819366}
- {x: -0.000000029802322, y: -0.11922422, z: -0.5381937}
- {x: -0.000000029802322, y: -0.11922422, z: -0.23819366}
- {x: -0.000000029802322, y: -0.11922422, z: 0.06180635}
- {x: -0.000000029802322, y: -0.11922422, z: 0.3618064}
- {x: -0.000000029802322, y: -0.11922422, z: 0.66180634}
- {x: -0.000000029802322, y: -0.11922422, z: 0.9618064}
- {x: -0.000000029802322, y: -0.11922422, z: 1.2618064}
- {x: -0.000000029802322, y: 0.18077579, z: -2.9381933}
- {x: -0.000000029802322, y: 0.18077579, z: -2.6381934}
- {x: -0.000000029802322, y: 0.18077579, z: -2.3381934}
- {x: -0.000000029802322, y: 0.18077579, z: -2.0381937}
- {x: -0.000000029802322, y: 0.18077579, z: -1.7381936}
- {x: -0.000000029802322, y: 0.18077579, z: -1.4381937}
- {x: -0.000000029802322, y: 0.18077579, z: -1.1381937}
- {x: -0.000000029802322, y: 0.18077579, z: -0.83819366}
- {x: -0.000000029802322, y: 0.18077579, z: -0.5381937}
- {x: -0.000000029802322, y: 0.18077579, z: -0.23819366}
- {x: -0.000000029802322, y: 0.18077579, z: 0.06180635}
- {x: -0.000000029802322, y: 0.18077579, z: 0.3618064}
- {x: -0.000000029802322, y: 0.18077579, z: 0.66180634}
- {x: -0.000000029802322, y: 0.18077579, z: 0.9618064}
- {x: -0.000000029802322, y: 0.18077579, z: 1.2618064}
- {x: -0.000000029802322, y: 0.18077579, z: 1.5618063}
- {x: -0.000000029802322, y: 0.18077579, z: 1.8618064}
- {x: -0.000000029802322, y: 0.18077579, z: 2.1618063}
- {x: -0.000000029802322, y: 0.4807758, z: -2.9381933}
- {x: -0.000000029802322, y: 0.4807758, z: -2.6381934}
- {x: -0.000000029802322, y: 0.4807758, z: -2.3381934}
- {x: -0.000000029802322, y: 0.4807758, z: -2.0381937}
- {x: -0.000000029802322, y: 0.4807758, z: -1.7381936}
- {x: -0.000000029802322, y: 0.4807758, z: -1.4381937}
- {x: -0.000000029802322, y: 0.4807758, z: -1.1381937}
- {x: -0.000000029802322, y: 0.4807758, z: -0.83819366}
- {x: -0.000000029802322, y: 0.4807758, z: -0.5381937}
- {x: -0.000000029802322, y: 0.4807758, z: -0.23819366}
- {x: -0.000000029802322, y: 0.4807758, z: 0.06180635}
- {x: -0.000000029802322, y: 0.4807758, z: 0.3618064}
- {x: -0.000000029802322, y: 0.4807758, z: 0.66180634}
- {x: -0.000000029802322, y: 0.4807758, z: 0.9618064}
- {x: -0.000000029802322, y: 0.4807758, z: 1.2618064}
- {x: -0.000000029802322, y: 0.4807758, z: 1.5618063}
- {x: -0.000000029802322, y: 0.4807758, z: 1.8618064}
- {x: -0.000000029802322, y: 0.4807758, z: 2.1618063}
- {x: -0.000000029802322, y: 0.7807758, z: -2.3381934}
- {x: -0.000000029802322, y: 0.7807758, z: -2.0381937}
- {x: -0.000000029802322, y: 0.7807758, z: -1.7381936}
- {x: -0.000000029802322, y: 0.7807758, z: -1.4381937}
- {x: -0.000000029802322, y: 0.7807758, z: -1.1381937}
- {x: -0.000000029802322, y: 0.7807758, z: -0.83819366}
- {x: -0.000000029802322, y: 0.7807758, z: -0.5381937}
- {x: -0.000000029802322, y: 0.7807758, z: -0.23819366}
- {x: 0.29999998, y: -0.11922422, z: -2.6381934}
- {x: 0.29999998, y: -0.11922422, z: -2.3381934}
- {x: 0.29999998, y: -0.11922422, z: -2.0381937}
- {x: 0.29999998, y: -0.11922422, z: -1.7381936}
- {x: 0.29999998, y: -0.11922422, z: -1.4381937}
- {x: 0.29999998, y: -0.11922422, z: -1.1381937}
- {x: 0.29999998, y: -0.11922422, z: -0.83819366}
- {x: 0.29999998, y: -0.11922422, z: -0.5381937}
- {x: 0.29999998, y: -0.11922422, z: -0.23819366}
- {x: 0.29999998, y: -0.11922422, z: 0.06180635}
- {x: 0.29999998, y: -0.11922422, z: 0.3618064}
- {x: 0.29999998, y: -0.11922422, z: 0.66180634}
- {x: 0.29999998, y: -0.11922422, z: 0.9618064}
- {x: 0.29999998, y: 0.18077579, z: -2.9381933}
- {x: 0.29999998, y: 0.18077579, z: -2.6381934}
- {x: 0.29999998, y: 0.18077579, z: -2.3381934}
- {x: 0.29999998, y: 0.18077579, z: -2.0381937}
- {x: 0.29999998, y: 0.18077579, z: -1.7381936}
- {x: 0.29999998, y: 0.18077579, z: -1.4381937}
- {x: 0.29999998, y: 0.18077579, z: -1.1381937}
- {x: 0.29999998, y: 0.18077579, z: -0.83819366}
- {x: 0.29999998, y: 0.18077579, z: -0.5381937}
- {x: 0.29999998, y: 0.18077579, z: -0.23819366}
- {x: 0.29999998, y: 0.18077579, z: 0.06180635}
- {x: 0.29999998, y: 0.18077579, z: 0.3618064}
- {x: 0.29999998, y: 0.18077579, z: 0.66180634}
- {x: 0.29999998, y: 0.18077579, z: 0.9618064}
- {x: 0.29999998, y: 0.18077579, z: 1.2618064}
- {x: 0.29999998, y: 0.18077579, z: 1.5618063}
- {x: 0.29999998, y: 0.18077579, z: 1.8618064}
- {x: 0.29999998, y: 0.4807758, z: -2.9381933}
- {x: 0.29999998, y: 0.4807758, z: -2.6381934}
- {x: 0.29999998, y: 0.4807758, z: -2.3381934}
- {x: 0.29999998, y: 0.4807758, z: -2.0381937}
- {x: 0.29999998, y: 0.4807758, z: -1.7381936}
- {x: 0.29999998, y: 0.4807758, z: -1.4381937}
- {x: 0.29999998, y: 0.4807758, z: -1.1381937}
- {x: 0.29999998, y: 0.4807758, z: -0.83819366}
- {x: 0.29999998, y: 0.4807758, z: -0.5381937}
- {x: 0.29999998, y: 0.4807758, z: -0.23819366}
- {x: 0.29999998, y: 0.4807758, z: 0.06180635}
- {x: 0.29999998, y: 0.4807758, z: 0.3618064}
- {x: 0.29999998, y: 0.4807758, z: 0.66180634}
- {x: 0.29999998, y: 0.4807758, z: 0.9618064}
- {x: 0.29999998, y: 0.4807758, z: 1.2618064}
- {x: 0.29999998, y: 0.4807758, z: 1.5618063}
- {x: 0.29999998, y: 0.7807758, z: -2.3381934}
- {x: 0.29999998, y: 0.7807758, z: -2.0381937}
- {x: 0.29999998, y: 0.7807758, z: -1.7381936}
- {x: 0.29999998, y: 0.7807758, z: -1.4381937}
- {x: 0.29999998, y: 0.7807758, z: -1.1381937}
- {x: 0.29999998, y: 0.7807758, z: -0.83819366}
- {x: 0.6, y: -0.11922422, z: -1.4381937}
- {x: 0.6, y: -0.11922422, z: -1.1381937}
- {x: 0.6, y: -0.11922422, z: -0.83819366}
- {x: 0.6, y: -0.11922422, z: -0.5381937}
- {x: 0.6, y: -0.11922422, z: -0.23819366}
- {x: 0.6, y: -0.11922422, z: 0.06180635}
- {x: 0.6, y: 0.18077579, z: -2.9381933}
- {x: 0.6, y: 0.18077579, z: -2.6381934}
- {x: 0.6, y: 0.18077579, z: -2.3381934}
- {x: 0.6, y: 0.18077579, z: -2.0381937}
- {x: 0.6, y: 0.18077579, z: -1.7381936}
- {x: 0.6, y: 0.18077579, z: -1.4381937}
- {x: 0.6, y: 0.18077579, z: -1.1381937}
- {x: 0.6, y: 0.18077579, z: -0.83819366}
- {x: 0.6, y: 0.18077579, z: -0.5381937}
- {x: 0.6, y: 0.18077579, z: -0.23819366}
- {x: 0.6, y: 0.18077579, z: 0.06180635}
- {x: 0.6, y: 0.18077579, z: 0.3618064}
- {x: 0.6, y: 0.18077579, z: 0.66180634}
- {x: 0.6, y: 0.18077579, z: 0.9618064}
- {x: 0.6, y: 0.18077579, z: 1.2618064}
- {x: 0.6, y: 0.4807758, z: -2.6381934}
- {x: 0.6, y: 0.4807758, z: -2.3381934}
- {x: 0.6, y: 0.4807758, z: -2.0381937}
- {x: 0.6, y: 0.4807758, z: -1.7381936}
- {x: 0.6, y: 0.4807758, z: -1.4381937}
- {x: 0.6, y: 0.4807758, z: -1.1381937}
- {x: 0.6, y: 0.4807758, z: -0.83819366}
- {x: 0.6, y: 0.4807758, z: -0.5381937}
- {x: 0.6, y: 0.4807758, z: -0.23819366}
- {x: 0.6, y: 0.4807758, z: 0.06180635}
- {x: 0.6, y: 0.4807758, z: 0.3618064}
- {x: 0.6, y: 0.4807758, z: 0.66180634}
- {x: 0.9, y: 0.18077579, z: -2.0381937}
- {x: 0.9, y: 0.18077579, z: -1.7381936}
- {x: 0.9, y: 0.18077579, z: -1.4381937}
- {x: 0.9, y: 0.18077579, z: -1.1381937}
- {x: 0.9, y: 0.18077579, z: -0.83819366}
- {x: 0.9, y: 0.18077579, z: -0.5381937}
- {x: 0.9, y: 0.18077579, z: -0.23819366}
- {x: 0.9, y: 0.18077579, z: 0.06180635}
colliders:
- {fileID: 1031304347490252193}
percentSubmerged: 0

vel: {x: 0, y: 0, z: 0}
engineSound: {fileID: 4709031650991942137}
waterSound: {fileID: 3376468742497974653}
torque: 5
steeringTorque: 5
upwardTorque: 15
horsePower: 18
enginePosition: {x: 0, y: 0.05, z: -3.31}
--- !u!114 &6727757724182940452

7
Assets/Unity Physics Items/Systems/ApplyBuoyancyForceSystem.cs


[ReadOnly]
public BufferFromEntity<VoxelHeight> heightBuffer;
public void Execute(Entity entity, int index, ref Translation pos, ref Rotation rot, ref PhysicsVelocity vel, ref PhysicsMass mass, ref PhysicsDamping damping, ref BuoyantData data)
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, ref PhysicsMass mass, ref PhysicsDamping damping, [ReadOnly] ref BuoyantData data)
{
DynamicBuffer<VoxelOffset> offsets = offsetBuffer[entity];
DynamicBuffer<VoxelHeight> heights = heightBuffer[entity];

vel.ApplyImpulse(mass, pos, rot, force * dt, wp);
}
}
//Apply drag
//data.percentSubmerged = Mathf.Lerp(data.percentSubmerged, submergedAmount, 0.25f);
//damping.Linear = data.baseDrag + (data.baseDrag * (data.percentSubmerged * 10f));
//damping.Angular = data.baseAngularDrag + (data.percentSubmerged * 0.5f);
}
}
}

29
Assets/Unity Physics Items/Systems/DriveSystem.cs


}
[BurstCompile]
public struct DriveWithInputJob : IJobForEachWithEntity<Translation, Rotation, PhysicsVelocity, PhysicsMass, DrivingData>
public struct DriveWithInputJob : IJobForEachWithEntity<Translation, Rotation, PhysicsVelocity, PhysicsMass, DrivingData, InputData>
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, [ReadOnly] ref PhysicsMass mass, ref DrivingData data)
public void Execute(Entity entity, int index, [ReadOnly] ref Translation pos, [ReadOnly] ref Rotation rot, ref PhysicsVelocity vel, [ReadOnly] ref PhysicsMass mass, ref DrivingData driveData, ref InputData inputData)
var wp = math.transform(entityTransform, data.engineOffset+mass.CenterOfMass);
if (wp.y <= -0.1f) // if the engine is deeper than 0.1
{
data.throttle = Mathf.Clamp(data.throttle, 0f, 1f); // clamp for reasonable values
var wp = math.transform(entityTransform, driveData.engineOffset);// + mass.CenterOfMass);
//if (wp.y <= -0.1f) // if the engine is deeper than 0.1
//{
inputData.throttle = Mathf.Clamp(inputData.throttle, 0f, 1f); // clamp for reasonable values
var force = (forward * data.throttle * data.horsePower) / mass.InverseMass; //divide by iMass to counteract mass in impulse method
var force = (forward * inputData.throttle * driveData.horsePower) / mass.InverseMass; //divide by iMass to counteract mass in impulse method
//Turning
var torque = (data.throttle * new float3(-1, 0, 0)) / mass.InverseInertia;
data.steering = Mathf.Clamp(data.steering, -1f, 1f); // clamp for reasonable values
var sTorque = new float3(0f, data.torque, -data.torque * .5f) * data.steering / mass.InverseInertia;
//Lift the nose up
var upTorque = (inputData.throttle * new float3(-1, 0, 0) * driveData.upwardTorque) / mass.InverseInertia;
vel.ApplyAngularImpulse(mass, upTorque * dt);
//Turning
// var torque = (data.throttle * new float3(-1, 0, 0)) / mass.InverseInertia;
inputData.steering = Mathf.Clamp(inputData.steering, -1f, 1f); // clamp for reasonable values
var sTorque = new float3(0f, driveData.steeringTorque, -driveData.steeringTorque * .5f) * inputData.steering / mass.InverseInertia;
}
//}
}
}
}

6
Assets/Unity Physics Items/Systems/InputSystem.cs


if (Time.time < startTime)
return;
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref DrivingData data ) =>
Entities.ForEach((Entity entity, ref Translation pos, ref Rotation rot, ref InputData data ) =>
{
if (data.isHuman)
{

else
{
AIController_DOTS2.GetInputs(entity, pos.Value, rot.Value, out data.throttle, out data.steering);
if (data.throttle < .01f)
Debug.Log($"{Time.time} Throttle is zero");
AIController_DOTS.GetInputs(entity, pos.Value, rot.Value, out data.throttle, out data.steering);
}
});
}

126
Assets/Unity Physics Items/AIController_DOTS2.cs


using BoatAttack;
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.AI;
class PathData2
{
public Vector3[] pathPoints;
public int currentPathPoint;
public WaypointGroup.Waypoint currentWaypoint;
public bool foundPath;
public bool nearEnd;
public Vector3 storedPosition;
};
public class AIController_DOTS2 : MonoBehaviour
{
static AIController_DOTS2 main;
public float nearDistance = 8f;
Dictionary<Entity, PathData2> paths;
private void Awake()
{
if (main != null && main != this)
{
Destroy(this);
return;
}
main = this;
paths = new Dictionary<Entity, PathData2>();
}
private void Update()
{
foreach (var path in paths)
{
if (path.Value.nearEnd || !path.Value.foundPath)
CalculatePath(path.Value);
}
}
public static void Register(Entity entity, Vector3 pos)
{
if (main.paths.ContainsKey(entity))
return;
PathData2 data = new PathData2();
data.currentWaypoint = WaypointGroup.instance.GetClosestWaypoint(pos);
data.storedPosition = pos;
data.nearEnd = true;
main.paths.Add(entity, data);
}
public static void GetInputs(Entity entity, float3 pos, quaternion rot, out float throttle, out float steering)
{
main.GetInputsInternal(entity, pos, rot, out throttle, out steering);
}
void GetInputsInternal(Entity entity, float3 pos, quaternion rot, out float throttle, out float steering)
{
throttle = steering = 0;
//Do we have data?
PathData2 data;
if (!paths.TryGetValue(entity, out data) || data.pathPoints == null)
return;
data.storedPosition = pos; //Store position for navmesh calculations
if (data.currentPathPoint < data.pathPoints.Length && data.foundPath)
{
//Get angle to the destination and the side
Vector3 normDir = data.pathPoints[data.currentPathPoint] - (Vector3)pos;
normDir = normDir.normalized;
var forward = math.forward(rot);
float dot = Vector3.Dot(normDir, forward);
//float angle = Mathf.Acos (dot) * Mathf.Rad2Deg;
float targetSide = Vector3.Cross(forward, normDir).y;//positive on right side, negative on left side
steering = Mathf.Clamp(targetSide, -1.0f, 1.0f);
throttle = dot > 0 ? 1f : 0.25f;
if ((Vector3.Distance(pos, data.pathPoints[data.currentPathPoint])) < nearDistance) // If we are close to the current point on the path get the next
{
data.currentPathPoint++; // Move on to next point
if (data.currentPathPoint >= data.pathPoints.Length)
data.nearEnd = true;
}
}
}
void CalculatePath(PathData2 data)
{
var wp = WaypointGroup.instance.GetNextWaypoint(data.currentWaypoint);
var offset = (UnityEngine.Random.value * 2f - 1f) * wp.WPwidth * Vector3.left;
var curWPPos = wp.point + wp.rotation * offset;
var navPath = new NavMeshPath(); // New nav path
NavMesh.CalculatePath(data.storedPosition, curWPPos, 255, navPath);
if (navPath.status == NavMeshPathStatus.PathComplete) // if the path is good(complete) use it
{
data.currentWaypoint = wp;
data.pathPoints = navPath.corners;
data.currentPathPoint = 1;
data.foundPath = true;
data.nearEnd = false;
}
else if (navPath == null || navPath.status == NavMeshPathStatus.PathInvalid) // if the path is bad, we havent found a path
{
data.foundPath = false;
}
}
}

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


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