[BurstCompile]
public partial struct MoveJob : IJobEntity
{
public float2 MoveAxes;
public float DeltaTime;
public bool IsSprinting;
private void Execute(ref MoveInput moveData, ref LocalTransform localTransform, in SpeedBoost? speedBoost = null)
{
MoveAxes = math.normalizesafe(MoveAxes);
moveData.SpeedModifier = 1f;
if (MoveAxes.y < 0)
{
moveData.SpeedModifier = 0.5f;
}
else if (IsSprinting)
{
moveData.SpeedModifier = 2f;
}
if (speedBoost != null)
{
moveData.SpeedModifier *= speedBoost.Value.Modifer;
}
float3 dir = new float3(MoveAxes.x, 0, MoveAxes.y);
localTransform.Position += dir * moveData.SpeedModifier * 10f * DeltaTime;
moveData.Move = MoveAxes;
}
}
#Is it possible to have optional ICopmonentData parameters in a IJobEntity?
1 messages · Page 1 of 1 (latest)
use a ComponentLookup like ComponentLookup<SpeedBoost> SpeedBoostLookup and then you can simply check if the entity has that component and do some logic based on that
If you're going to set the speed modifier every frame, why not just have a separate job that writes to the modifier when you have a speedboost? Though you might want to look into an attribute system like Trove Attributes or Tertle's stats/reaction library.
But also other ways you can solve it, SpeedBoost could instead be an IEnableable component for example. Or you could always have speedbost on the entity with a value of "1", and just modify it instead of adding it.
You could also write your job as an IJobChunk instead, and just check if the archetype has the speedboost to begin with. Though that's a bit more complex. Thelebaron's solution would also work, though it might be slow in the long run?
Though before that you might want to reevalute if you should be writing this as a job at all. If it's a character controller meant to be executed on a single entity then you might just want to get the entity as a singleton instead and just use SystemAPI to check what fields are on it.