dotween icon indicating copy to clipboard operation
dotween copied to clipboard

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

Open andrewle9510 opened this issue 2 years ago • 6 comments

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

andrewle9510 avatar May 23 '23 11:05 andrewle9510

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.

Demigiant avatar May 23 '23 11:05 Demigiant

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

andrewle9510 avatar May 24 '23 03:05 andrewle9510

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 avatar May 24 '23 09:05 Demigiant

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);
			}
		});
	}

Demigiant avatar May 24 '23 09:05 Demigiant

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.

andrewle9510 avatar May 24 '23 09:05 andrewle9510

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?

Demigiant avatar May 24 '23 10:05 Demigiant