Moving an object by few units up and stopping it , but so like it looks like an animation .

I want to make a platform appear and make it look like it was animated . I dont know how to make Transform.Translate transition to position because in my game it just appears in the final position instead of ‘‘traveling’’ to final position.

Hello there,

If you want to actually use animations, This Tutorial should tell you everything you need.

If you want to animate through code, you’re going to want to use Lerps and smoothing methods. Here’s a good read.


Hope that helps!

Cheers,

~LegendBacon

Alternatively, if you want a really fast solution (@Legend_Bacon 's script method is still better) you could just multiply the vector by Time.deltaTime, which will make the motion last for 1 second (and multiply by another number as a speed modifier). This won’t work if it’s not in Update/Coroutine, because if you call this only once you would simply move the object a very small amount.

You’ll want to use Vector3.Slerp()
or
Vector3.Lerp()

Here’s some untested code:

public float speed = 1;

	public void Move(Vector3 vector) {
		StartCoroutine(MovePlatform(vector));
	}

	private IEnumerator MovePlatform(Vector3 vector) {

		float delta = 0;								
		Vector3 startPosition = transform.position;			
		Vector3 endPosition = transform.position + vector;	
		
		while (transform.position != endPosition) {			
			delta += Time.deltaTime / speed;
			transform.position = Vector3.Lerp(startPosition, endPosition, delta);
			yield return new WaitForSeconds(Time.deltaTime);
		}

		yield return null;
	}