Hi, I’ve been trying to program in ECS lately as it is still new to me, and I encountered an issue when attempting to create a spinning cube.
this is my current code
using Unity.Entities;
using Unity.Jobs;
using Unity.Transforms;
using UnityEngine;
[AlwaysSynchronizeSystem]
public class CubeRotationSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltaTime = World.Time.DeltaTime;
Entities.ForEach((ref Rotation rot, in CubeRotationData data) =>
{
Quaternion rotation = Quaternion.Euler(data.direction * data.speed * deltaTime);
rot.Value = rot.Value * rotation;
}).Run();
return default;
}
}
data.directly contains a float3 of the direction and data.speed a float of… well the speed, the data never changes on this level.
the cube correctly spins but like every 5 seconds or so I can see that the cube kind of stutters before restarting to turn properly
where do you think the problem could come from ?