Friction to slow down vector based speed.


     // Update point
		point.x = input.getMouseX();
		point.y = input.getMouseY();
		
		// Apply dampening
		speed.sub(dampening);
		
		// Move player
		if(range.intersects(MouseGhost.rect)) {
			// Update speed/direction
			speed = point.sub(pos).normalise().negate();
			
			pos.add(speed.scale(point.distance(pos)/100));
		}

Basically I’m checking if the mouse is inside the range of the tile. If so I want it to increase the speed. Then when the mouse leaves the range, I’d like it to continue on a bit. I figured if I subtracted the dampening vector from the speed vector it would slow down but that doesnt seem to do it. What am I doing wrong?

Instead multiply by a dampening factor. (less than 1.0)

You can also decrease linearly if you want it to look different. The way BurntPizza suggests is exponential (which is totally fine and probably looks the best), but if you want it to decrease linearly you could do a check like this:


     // Update point
      point.x = input.getMouseX();
      point.y = input.getMouseY();
      
      // Apply dampening
      if(speed.abs().length() != 0.0) {
         speed.sub(dampening);
      }
      
      // Move player
      if(range.intersects(MouseGhost.rect)) {
         // Update speed/direction
         speed = point.sub(pos).normalise().negate();
         
         pos.add(speed.scale(point.distance(pos)/100));
      }

And that should work. I think. I say I think because it’s late and my mind isn’t really in it right now.