Skip to content

Game.Tools.Animation

Assembly: Game (inferred from project files)
Namespace: Game.Tools

Type: struct

Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
Component used by the game's ECS to store per-entity animation state. Holds target and current transform data (position/rotation), sway-related state for procedural motion, and a push factor used to control how strongly the entity moves toward its target. Includes a small helper to convert the stored position/rotation into a Game.Objects.Transform.


Fields

  • public float3 m_TargetPosition
    Stores the target/world position the animation should move toward. Used by animation/physics systems to compute interpolation or forces.

  • public float3 m_Position
    Current position of the entity as tracked by the animation component.

  • public quaternion m_Rotation
    Current rotation of the entity. Combined with m_Position to produce a Transform.

  • public float3 m_SwayPivot
    Pivot point for procedural sway calculations. Typically used as the origin for sway offsets.

  • public float3 m_SwayPosition
    Current sway offset applied to the entity's position (procedural animation state).

  • public float3 m_SwayVelocity
    Velocity used by the sway integrator (e.g., for spring/damper simulation) to update m_SwayPosition.

  • public float m_PushFactor
    Scalar factor that controls the strength of pushing/movement toward the target (or how much external forces influence the animation).

Properties

  • None. This is a plain struct component with public fields intended for fast ECS access.

Constructors

  • public Animation()
    As a value type (struct), Animation has the default parameterless constructor provided by C#. Fields will be default-initialized (float3.zero, quaternion.identity is not automatically guaranteed for quaternion — initialize explicitly if required). It's recommended to explicitly initialize fields when creating instances to avoid ambiguity.

Example recommended initialization:

var anim = new Animation
{
    m_Position = float3.zero,
    m_Rotation = quaternion.identity,
    m_TargetPosition = float3.zero,
    m_SwayPivot = float3.zero,
    m_SwayPosition = float3.zero,
    m_SwayVelocity = float3.zero,
    m_PushFactor = 1f
};

Methods

  • public Transform ToTransform() : Game.Objects.Transform
    Helper that converts the component's position and rotation into a Game.Objects.Transform instance. Useful when systems need the transform representation used elsewhere in the codebase.

Behavior: - Returns new Transform(m_Position, m_Rotation). - Does not include sway offsets — if you want sway applied, add m_SwayPosition to m_Position before converting.

Usage Example

using Unity.Mathematics;
using Unity.Entities;
using Game.Tools;
using Game.Objects;

// Create and initialize an Animation component and add it to an entity
var anim = new Animation
{
    m_Position = new float3(0f, 5f, 0f),
    m_Rotation = quaternion.identity,
    m_TargetPosition = new float3(10f, 5f, 0f),
    m_SwayPivot = float3.zero,
    m_SwayPosition = float3.zero,
    m_SwayVelocity = float3.zero,
    m_PushFactor = 0.8f
};

EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(someEntity, anim);

// Later in a system, convert to Transform for rendering or other subsystems
Animation currentAnim = entityManager.GetComponentData<Animation>(someEntity);
Transform tf = currentAnim.ToTransform();
// If you want sway applied:
tf.position += currentAnim.m_SwayPosition;