Damping / Smoothing

Hi

I use the script below to move a target (objectToMove) up and down on screen, following the finger.

This works well, however, the start stop motion is hard, and I’d like to soften it, e.g. when i stop moving my finger, or stop touching the screen, the objectToMove will slow down to a stop rather than hard stop.

I’ve tried to incorporate SmoothDamp but I can’t get that to work… obviously I’m not understanding it correctly. So I’m hoping someone might be able to point me in the right direction for this.
Thanks

          		  	if (ChangeInY < 0) 
          		  	{ 
          		  		movementDirection = -1;
          		  		
						while (objectToMove.transform.position.y > 0) //clamping
						{ 		
							objectToMove.transform.Translate (directionYDown * Time.deltaTime*objectSpeed, Space.World);														
						}
					}
				
	
					else if (ChangeInY > 0)
					{
						movementDirection = 1;
						
						while (objectToMove.transform.position.y < 570)
						{ 
							objectToMove.transform.Translate (directionY * Time.deltaTime*objectSpeed, Space.World);	
						}

well in order to use smooth damp you need a velocity variable for it. now other ones that are similar would be vertor3.lerp. one way you could cheat to if you just need to learn by watching code is that in your standard assets folder saying that you imported it there is the smooth follow. if you look in the late update function for the camera . it’s pretty much the same thing you are trying to do.

just because a script is on a certain object it doesn’t always means that it’s only meant for it lol :slight_smile: good luck

You could use the physics engine. depending on what you are doing the movement might be more interesting to look at anyway.

Just use your touch input to move an intermediate gameObject the way you do now and connect it to the object you actually want to move with a springJoint.