Some background to the question:
I am attempting to animate and control a large multi sprite 2D Boss character for a platforming game.
Up until this point I had been assigning individual animators for each of the limbs and using RigidBody2D to control the movement of each one respectively.
This worked fine except for one thing: synchronizing each animation state with the other controllers was a huge pain in the ass and error prone.
Hence my next step was creating one single Animation Controller using multiple layers to manage the animations together. This worked great, on the animation side of things. Catch was that now it had become completely impossible to alter the Transform of the the individual limbs (any child component below the animator)
- Boss Character (main scripts and animator)
-- BossHead (collider)
-- SpriteHolder
-- BossTorso (collider)
-- SpriteHolder
-- BossLeftHand (collider)
-- SpriteHolder
-- BossRightHand (collider)
-- SpriteHolder
- I have tried using transform.Translate instead of a RigidBody2D (same result)
- I have tried checking apply root motion in the animator (same result)
- I have doubly checked that no transform values were being modified during the animation (same result)
Unity version 2018.2.11
This use case does not seem to be all that unusual so there must be a correct workflow for this. Question is, what is the Unity correct way to achieve this?
EDIT: Code That updates the RigidBody2D
Void LateUpdate() {
if (_path == null)
return;
if (_currentWaypoint >= _path.vectorPath.Count)
{
if (!_reachedEndOfPath)
{
_reachedEndOfPath = true;
_rb.velocity = Vector2.zero;
_callback?.Invoke();
}
return;
}
else
{
_reachedEndOfPath = false;
}
Vector2 direction = ((Vector2)_path.vectorPath[_currentWaypoint] - _rb.position).normalized;
Vector2 force = direction * speed * Time.deltaTime;
_rb.AddForce(force);
float distance = Vector2.Distance(_rb.position, _path.vectorPath[_currentWaypoint]);
if (distance <= _nextWaypointDistanceMargin)
_currentWaypoint++;
}
Example of the effect I am attempting to create:
Main boss with two disembodied hands that can float around to chase the player.