Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.3k stars 346 forks source link

ChangeEndValue works with transform.DoMove but not work with rigidbody2d.DoMove #634

Open andrewle9510 opened 1 year ago

andrewle9510 commented 1 year ago
Tweener _tweener = rb2d.DOMove(m_playerCharacter.transform.position, _distance / m_moveSpeed);
        _tweener.OnUpdate(() =>
        {
            _distance = Vector2.Distance(m_playerCharacter.transform.position, transform.position);
            if (_distance > 1f)
            {
                _tweener.ChangeEndValue((Vector2)m_playerCharacter.transform.position, _distance / m_moveSpeed, true);
            }
        });

this is my code. please help me

Demigiant commented 1 year ago

Ahoy, I can't make a test right now but could you try to cast the change value to a Vector3? That should fix it in theory.

andrewle9510 commented 1 year ago

Hi Demigiant, unfortunately dotween gave me an error, not a warning. it does not allow to use Vector3

Demigiant commented 1 year ago

Ahoy, Sorry from the phone I didn't realize we werre talking about a rigidbody2d (even if it was in the title, agh) so Vector3 didn't make sense. I just made this test and it all works perfectly:

IEnumerator Start()
{
  Tweener t = rigibody2d.DOMove(new Vector2(2, 0), 2);
  yield return new WaitForSeconds(1);
  t.ChangeEndValue(new Vector2(-2, 0), 2, true);
}

What do you mean by not working? If nothing seems to happen then maybe some calculations like distance are going wrong?

Demigiant commented 1 year ago

I also made this test to check OnUpdate and it works perfectly too (though I made sure the value wasn't changed repeatedly):

        void Start()
    {
        Tweener t = rigibody2d.DOMove(new Vector2(2, 0), 2);
        bool valueChanged = false;
        t.OnUpdate(() =>
        {
            if (!valueChanged && rigibody2d.position.x > 1) {
                Debug.Log("Changing value");
                valueChanged = true;
                t.ChangeEndValue(new Vector2(-2, 0), 2, true);
            }
        });
    }
andrewle9510 commented 1 year ago

Hi, i try to make enemy follow player. those code i posted, it gave no warning or error. but the enemy does not even move. i think it is not the distance problem, because i change the rb2d => transform. it works like a charm. i think maybe the casting from vector3 => vector2 is the problem, because when i dont cast, the enemy did move. but not change the end value because it requires vector2 instead of vector3.

Demigiant commented 1 year ago

I'm confused as to why this wouldn't work other than external factors. Could you make a barebone project that replicates this issue and send it to me, so I can test it out?