#How to make billboarding effect with DOTS

1 messages · Page 1 of 1 (latest)

signal cove
#

Is there some tutorial on how to make billboarding effect with Unity DOTS/ECS? I tried this but the objects literally rotate to look at the camera instead of being a true billboard effect.

protected override void OnUpdate()
{
Transform cameraTransform = Camera.main.transform;
var cameraPosition = (float3)cameraTransform.position;

    foreach ((var localTransform, Entity entity) in SystemAPI.Query<RefRW<LocalTransform>>().WithEntityAccess()
                 .WithAll<Billboard>())
    {
        float3 objectPosition = localTransform.ValueRO.Position;
        float3 direction = math.normalize(cameraPosition - objectPosition);
        quaternion targetRotation = quaternion.LookRotationSafe(direction, math.up());

        localTransform.ValueRW.Rotation = targetRotation;
    }
}
limber kite
#

Can you describe what is "Billboarding" effect for you?

signal cove
#

Don't starve

#

always facing the camera's rotation exactly

#

I actually did this and it works like I want it:

[UpdateInGroup(typeof(SimulationSystemGroup))]
public partial class BillboardSystem : SystemBase
{
    private readonly Transform _cameraTransform = Camera.main?.transform;

    protected override void OnCreate()
    {
        RequireForUpdate<Billboard>();
    }

    protected override void OnUpdate()
    {
        foreach (var localTransform in SystemAPI.Query<RefRW<LocalTransform>>().WithAll<Billboard>())
        {
            quaternion targetRotation = _cameraTransform.rotation;

            localTransform.ValueRW.Rotation = targetRotation;
        }
    }
}

But I am pretty certain there's a better way of doing this

cobalt egret
#

that's about it

#

all you can improve - get camera transform separately

#

cache it in burst compatible component

#

and make this system bursted

signal cove
#

That's the part I'm interested, how would I get the transform separately?

#

Do I need to place some BillboardCameraAuthoring on my Camera GO?

#

I'm really new to DOTS so this way of working doesn't make sense to me yet 😄

cobalt egret
#

other system

#

that's about it

#

quaternion targetRotation = _cameraTransform.rotation; you just clal this in separate system

signal cove
#

Could you give me an example? I'm not sure what you mean. Should we be "calling" other systems from a system?

cobalt egret
#

you use other system

#

to store this data somewhere

#

and then you get this data in your system

signal cove
#

I thought systems aren't supposed to store data

cobalt egret
#

well, I didn't say to store that data on system

#

you use components for it

signal cove
#

Can you please give me an example?

#

"you use other system
to store this data somewhere"

#

this really confuses me

#

do you mean like a singleton system that only runs once, and caches the camera position?

cobalt egret