I have a hover car traffic system. (Easy Roads 3D has lane data, and I have converted what I need to series entity lane data. Highly recommend the asset… but I digress)
I have the following ECS Job that works fine, based on the Target, the Auto faces that point. This works fine. HOWEVER, it does not bank/roll the auto. So the movement seems “off”
public partial struct TrafficRotateJob : IJobEntity
{
public float deltaTime;
private const float rotationMinMagnatude = .01f;
public void Execute(ref LocalTransform localTransform, in RotationSpeed rotationSpeed, in TargetPosition targetPosition)
{
Vector3 targetLookRotation = targetPosition.value - localTransform.Position;
if (targetLookRotation.sqrMagnitude > rotationMinMagnatude)
{
Quaternion lookOnLook = Quaternion.LookRotation(targetLookRotation);
localTransform.Rotation = math.slerp(localTransform.Rotation, lookOnLook, deltaTime * rotationSpeed.value);
}
Here I have some old GameObject code that works fine for turning and banking
public GameObject ship;
public GameObject next; //next waypoint
private void TurnAndBank()
{
float rotationSpeed = 0.5f;
var targetLookRotation = next.transform.position - ship.transform.position;
if (targetLookRotation != Vector3.zero) //to avoid the "Look rotation viewing vector is zero" exception
{
Vector3 pos = transform.InverseTransformPoint(next.transform.position);
float zValue = 0;
if (pos.x > 1 || pos.x < -1)
{
zValue = -(pos.x * 4f);
}
var desiredRotation = Quaternion.Euler(ship.transform.eulerAngles.x, ship.transform.eulerAngles.y, zValue);
ship.transform.rotation = Quaternion.Lerp(ship.transform.rotation, desiredRotation, Time.deltaTime * rotationSpeed);
//------------------------------
//Rotate the Base of the auto
//var rotation = Quaternion.LookRotation(toTarget);
//ship.transform.rotation = Quaternion.Slerp(ship.transform.rotation, rotation, Time.deltaTime * rotationSpeed);
}
}
So… I am attempting to convert the GO process to a Job… but for starters InverseTransformPoint doesn’t exist, and looking into how to convert it got me down a rabbit hole, and then I thought; “someone has seen this before and I won’t spent two days repeating the process, I should just ask”
So here I am, does anyone know a way to turn toward the Target as well as Bank/Roll, within a ECS Job?
Thanks for any info