Textures are disappearing

I’m making a particle simulation.
I’m moving the particles to the mouse position when left mouse button is pressed.

After the particles reach the destination they disappear (that should not happen).

Code: https://pastebin.com/hMKvkRSP

What am i doing wrong?

When distance is = Vector2.Zero, then Normaize fails with NaN.

A nicer solution is to first get direction.Length() , check if it’s zero, and then normalize ‘direction’ manually by dividing direction/length. (it’s faster too since you skip an extra Sqrt.)

Ok, why doesn’t Normalize return zero then? It’s complicated! A zero result would still be wrong, It’s not a valid normal. It seems to fit in this situation but in many general cases it doesn’t work.

Vector3.Length is already doing a Sqrt … use LengthSquared to check for zero (it’s only the multiplications without the sqrt)

[but you’re right, Normalize would just do another sqrt by getting the length, so if you can spare it, it’s even better)

1 Like

thanks that worked perfectly :slight_smile:

1 Like