Smooth transition of object

Hello

I would like to make smooth transition when player moves from one position to another.

At this moment code looks like this:

if(Input.GetKey("down") || Input.GetKey("s"))
{
	transform.rotation = Quaternion.LookRotation(Vector3.back, Vector3.up);
	playerPosition.z += -1;
}

When player presses key, he is moved in the proper direction, but he just “disappears” from one location, and “appears” in another. I would like to make smooth transition, so it will look nicer for the player.

Additionally I would like to make limit of maximum number of moves per certain amount of time.

~Laran

1 Answer

1

Use delta time!

Example:

void Update(){
    if(Input.GetKey("down") || Input.GetKey("s")){
        transform.rotation = Quaternion.LookRotation(Vector3.back, Vector3.up);
        playerPosition.z += -1*Time.deltaTime;
    }
}

This makes that whole movement is smoother so player have to keep pressing button. I want to move player by 1 (when he presses button once), but make transition smooth, so he don't just appears in the destination position, but moves there.

Hmmm similar to pokemon move style? Click once: you move to next square?

Yes, exactly. My description is so chaotic :P

Ok, for that I use IEnumerators. I already answered it today. Check it here: http://answers.unity3d.com/questions/587866/get-an-object-to-move-to-a-position-for-a-fixed-ti.html#answer-587869 The question is different to your but I think the answer is quite similar. Tell me if it´s not clear and I´ll try to answer it specifically for this issue.

Thank you, it works:)