#Weird bone issue with Animation Rigging and DOTween

1 messages · Page 1 of 1 (latest)

whole mountain
#

I have an animation rigging setup of a fish. Its code does DOTweens for motion and "sway". It also breaks motion if a raycasthit collides with something. However, after 1 or 2 raycasthits, the last bone of the AR setup goes nuts.

#

This is the setup for the AR

#

All GO's under Rig 1 have a dampedtransform with correct bones assigned

#

and this is the entire code of the fish

#
{
    //Move vars
    [Range(1.0f, 30.0f)]
    public float deviateMaxAngle = 10.0f;
    public float speed;
    [Range(1.0f, 60.0f)]
    public float seekDistance = 40.0f;
    private Vector3 destination;
    public float bumpDistance = 1f;
    public float turnSpeed = 0.15f;
    private bool needsMove = true;
    Sequence movementSequence;
    private bool hasCollided = false;

    //Flip Flap vars
    public float swimSpeed;
    public GameObject firstBone;
    private bool flipFlapFinished = true;

    //Idle state vars
    public Vector2 waitSecondsRandomRange;
    private float waitSeconds;```
#
    {
        if(needsMove){
            MoveToDestination();
        }

        if(flipFlapFinished)
        {
            FlipFlap();
        }

        if(!hasCollided){
            RaycastHit hit;
            if(Physics.Raycast(transform.position, transform.forward, out hit, bumpDistance))
            {
                Debug.DrawRay(transform.position, transform.forward * hit.distance, Color.white);
                hasCollided = true;
                movementSequence.Kill();
                MoveToRadicalDestination();
            }
        }
        else
        {
            MoveToRadicalDestination();
        }
    }

    void MoveToDestination()
    {
        needsMove = false;
        GetDestination();
        movementSequence = DOTween.Sequence();
        movementSequence
        .Append(transform.DOLookAt(destination, turnSpeed).SetEase(Ease.Linear))
        .Append(transform.DOMove(destination, speed).SetEase(Ease.Linear))        
        .AppendCallback(() =>
            {
                StartCoroutine(StandIdle());
            }
        )
        .SetAutoKill(true);
    }

    void MoveToRadicalDestination()
    {
        needsMove = false;
        hasCollided = false;
        GetRadicalDestination();
        movementSequence = DOTween.Sequence();
        movementSequence
        .Append(transform.DOLookAt(destination, turnSpeed).SetEase(Ease.Linear))
        .Append(transform.DOMove(destination, speed).SetEase(Ease.Linear))        
        .AppendCallback(() =>
            {
                StartCoroutine(StandIdle());
            }
        )
        .SetAutoKill(true);
    }```
#
    {
        Vector3 testPosition = (transform.position + (transform.forward * seekDistance)) +
            new Vector3(
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle),
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle),
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle)
                );
        destination = testPosition;
    }

    void GetRadicalDestination()
    {
        Debug.Log("Goes to Radical Destination");
        Vector3 testPosition = (transform.position + (transform.forward * -1 * seekDistance))
        +new Vector3(
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle),
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle),
                Random.Range(deviateMaxAngle*-1, deviateMaxAngle)
                );
        destination = testPosition;
    }

    void FlipFlap()
    {
        flipFlapFinished = false;
        firstBone.transform.DOLocalRotate(new Vector3(0,0,12), swimSpeed, RotateMode.FastBeyond360).SetEase(Ease.InOutSine).SetRelative(true).SetLoops(2, LoopType.Yoyo)
        .OnComplete(()=>{
            flipFlapFinished = true;
        }).SetAutoKill(true);
    }

    IEnumerator StandIdle()
    {
        swimSpeed*=2f;
        waitSeconds = Random.Range(waitSecondsRandomRange.x, waitSecondsRandomRange.y);
        Debug.Log("Will idle for "+waitSeconds);
        yield return new WaitForSeconds(waitSeconds);
        swimSpeed*=0.5f;
        needsMove = true;
    }
    
}```
golden bronze
#

hasColided = true is immediately switched to hasCollided false

whole mountain
golden bronze
#

so your collision logic is glitched

whole mountain
#

I'm not sure how to move it to its own function since I'm not sure what's the conditional here 😅

golden bronze
#

yeah

#

it's very tricky

whole mountain
#

I can try putting the hasCollided in the RadicalDestination sequence oncomplete

#

does this sound like it would work?

#

Well that didn't work. When it collides, it just keeps looking for a new Radical destination

#

Lol

whole mountain
#

I think I found out what happens. Damped rotation accumulates if there's collision happening too often, and it propagates to the last bones. Eventually it becomes too much to handle. Is there a way to clear the damped transform after it has collided?