I am creating a 3D turn-based strategy game. I have a bunch of units with hitboxes of the head, arms, legs of the torso that are attached to the skeleton of the character. And when you play a character, part of the fps is eaten by the physics engine (this is understandable). The question is how to make the character get that he is not displayed in the camera and can pause the animation? It turns out that looped animation always works
foreach (var unit in Units)
{
if (unit.IsDead) continue;
if (Camera3DGround.IsPositionInFrustum(unit.Position))
unit.VisibleByPlayer = true;
else
unit.VisibleByPlayer = false;
}
WHERE
private bool _visibleByPlayer;
public bool VisibleByPlayer
{
get => _visibleByPlayer;
set
{
if (_visibleByPlayer == value) return;
_visibleByPlayer = value;
if (_visibleByPlayer)
{
_animationPlayer.Play(Animation.Get(AnimaPersonState.Idle3));
Show();
}
else
{
_animationPlayer.Stop();
Hide();
}
}
}