27-02-2021, 09:56 AM
(27-02-2021, 09:15 AM)zero16832 Wrote: According to the example you provided, I wrote a demo that uses the mouse to move. At first, the demo is normal, but the later movement slowly turns into the opposite direction. Why?
if (Input.GetMouseButton(0))
{
direction += moveDirection* moveSpeed;
softbody.AddForce(direction.normalized * moveSpeed, ForceMode.Acceleration);
}
It’s hard to tell just by looking at that code. However, the code doesn’t make a lot of sense to me:
You’re adding moveDirection * moveSpeed to direction, but you’re then normalizing it. This will make direction a vector of unit length, but then you multiply it by moveSpeed a second time.
No need to do the first multiplication if you’re normalizing the vector afterwards, as it will be unit length anyways. I don’t see anything that would reverse the movement direction though. Can you post the full code?