- Home /
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
Answer by MrVerdoux · Dec 02, 2013 at 03:09 PM
Use delta time!
http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html
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?
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.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
How can I create a smooth rigidbody2d movement? 1 Answer
Smoothly move 2D Sprite 2 Answers
Smooth Movement with RPC's 1 Answer
Multiple Cars not working 1 Answer