Skip to content

Commit

Permalink
Correct the use of FaceDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
laicasaane committed Oct 10, 2024
1 parent 4ed6577 commit 616e922
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Assets/Code/Components/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public struct SpriteElapsedTime : IComponentData
public struct FaceDirection : IComponentData
{
public sbyte value;

public readonly int GetFace()
=> math.select(-1, 1, value > 0);
}

public struct MoveSpeed : IComponentData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ in SystemAPI.Query<SpriteRendererRef, SpriteIndex, SpriteIndexPrevious, SpriteSh
var sprite = sheet.Sprites.Span[index];
var renderer = rendererRef.value.Value;
renderer.sprite = sprite;
renderer.flipX = faceDirection.value > 0;
renderer.flipX = faceDirection.GetFace() > 0;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void Execute(in FaceDirection faceDirection, ref LocalTransform transfor
var max = boundary.max;
var xToTheRight = math.select(position.x, min.x - padding, position.x > max.x + padding);
var xToTheLeft = math.select(position.x, max.x + padding, position.x < min.x - padding);
position.x = math.select(xToTheLeft, xToTheRight, faceDirection.value > 0);
position.x = math.select(xToTheLeft, xToTheRight, faceDirection.GetFace() > 0);

transform.Position = position;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Code/Systems.Simulation/MoveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ in MoveSpeed moveSpeed
, ref LocalTransform transform
)
{
transform.Position += new float3(moveSpeed.value * deltaTime, 0f, 0f) * faceDirection.value;
transform.Position += new float3(moveSpeed.value * deltaTime, 0f, 0f) * faceDirection.GetFace();
}
}
}
Expand Down

0 comments on commit 616e922

Please sign in to comment.