How do I have an Entity "LookAt" a WorldSpace Point?

In a SystemBase.ForEach, how do I “LookAt” a point?(aka rotate such that my game object faces this point.)

I found clues here: How do you set non-local rotation in ECS? (also: documentation feedback)

  • my code:
    Entities
    .WithName(“RotationSpeedSystem_ForEach”)
    .ForEach((ref Rotation rotation, ref Translation translation, ref LocalToWorld ltw, ref MovementDataEntity movementData, ref DroneDataEntity dd, ref PhysicsVelocity pv) =>
    {

//TRYING for Entity to look at me. My location: 5,20,54

UnityEngine.Vector3 newDir = UnityEngine.Vector3.RotateTowards(ltw.Forward, new UnityEngine.Vector3(5, 20, 54), 13f, 0f);

rotation.Value = quaternion.EulerXYZ(newDir.x, newDir.y, newDir.z);

I have some cool videos of 50,000 drones being rendered, but I need to figure out how to have them face me, and how to thrust slowly in their forward facing vector:

&

If I could have em face the player and apply thrust, I’d have 50,000 drones chasing me…

Solved:

float3 pos;
pos.x = playerPos.Value.x;
pos.y = playerPos.Value.y;
pos.z = playerPos.Value.z;

float3 pos2;

pos2.x = translation.Value.x;
pos2.y = translation.Value.y;
pos2.z = translation.Value.z;

float3 relativePos = pos - pos2;

// the second argument, upwards, defaults to Vector3.up

quaternion start = rotation.Value;
quaternion end = quaternion.LookRotation(relativePos, math.up());

//quaternion result=quaternion.sl
rotation.Value = end;

Anyone know how to slerp in dots?

1 Like

math.slerp()

1 Like

Yup, Cookie Stealer, 100% right.

Check out videos now: