Velocity calculation

Hi i need help to calculate the velocity of particles in my particle system.
I got my screen filled with particles and they should move to my mouse position when I left click.
Also i want the “gravity” from my mouse to affect the particles more when they are near to the mouse.

The problem I have is that the overshoot extremely when i hold left click on the same position because i just divide the movement vector by direction.Length.

Can someone help me out how to do it better?

Code: https://pastebin.com/ZQXUJWek

What behavior do you think you want? If you imagine rolling a ball down this parabola, when it reaches the bottom, it will overshoot and roll up the other side. Without friction it will continue rolling back and forth the same amount. Do you want it to slow as it reaches the bottom? Or roll back and forth less and less until it eventually comes to rest?

image

There are a bunch of different ways to add dampening or friction. If you want to limit the minimum value you divide by, you could try dividing by (constant + direction.length), or if you want to flatten the curve a little (too soon? :stuck_out_tongue:) you could divide by log(constant * direction.length).

You can see what these would do to your speed by plotting them. I use a base speed of 10 here.

image

1 Like

thx adding a constant gave me exactly the behavior i wanted :slight_smile: