1

Is there any way to get transform component from entity? I know, there is new library for it, cant find. I could find only Translation. Maybe it's related with another way of getting entities? Maybe with query.

Can anyone help. Thanks.

enter image description here

3 Answers 3

0

There isn't really a "transform" like the one that gameobjects have, but I suspect you're looking for LocalToWorld. Along with having a position property, it has things like Rotation, Up, Forward, etc. And it contains a matrix that you can use to multiply with a position to convert to to world coordinates. If you want to go from world to local, invert the matrix before doing the multiplication.

Sign up to request clarification or add additional context in comments.

Comments

0

LocalToWorld is a world transform. Both Translation and Rotation are local space.

using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;

float3 point = new float3( 0 , 0 , 0 );
Entities
    .ForEach( ( in LocalToWorld transform ) =>
    {
        float dist = math.distance( point , transform.Position );
        if( dist<5 )
        {
            /* something happens */
        }
    } )
    .WithBurst().ScheduleParallel();

Comments

-1
ComponentDataFromEntity<Translation> allTranslations = GetComponentDataFromEntity<Translation>(true);

....

public class TargetToDirectionSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities.
            WithNone<PlayerTag>().
            WithAll<ChaserTag>().
            ForEach((ref MoveData moveData, ref Rotation rot, in Translation pos, in TargetData targetData) =>
            {
                ComponentDataFromEntity<Translation> allTranslations = GetComponentDataFromEntity<Translation>(true);
                if (!allTranslations.Exists(targetData.targetEntity))
                {
                    return;
                }

                Translation targetPos = allTranslations[targetData.targetEntity];
                float3 dirToTarget = targetPos.Value - pos.Value;
                moveData.direction = dirToTarget;

            }).Run();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.