How do I make an object slowly come into the scene?
Hi guys,
I'm a beginner. Now I'm programming a demo to show how you need to assamble a part. I want to show the part and then make it slowly move to the defined position.
How can I do it?
This is what I got now but it's to fast and not smooth
public void Update()
{
if (stepCountUp == 1)
{
while (GameObjects[0].transform.position.x >= -2)
{
Time.timeScale = 0.000000000000001f;
GameObjects[0].transform.Translate(new Vector3(-2f, 0, 0) * speed * Time.deltaTime);
}
}
}
Best Answer
-
JimRodr ✭
Vector3 spot = Vector3.MoveTowards(transform.position, idealLocation, 0.01f);
transform.position = spot;I have had good success using MoveTowards to have objects slowly go from where they are to where I want them to end up. The third parameter is how much to move and can be calculated using a desired speed * Time.DeltaTime to be more precise/move smoother than a constant like 0.01f does.
1
Answers
This is probably a question that is more for the unity forum I am afraid.
Vector3 spot = Vector3.MoveTowards(transform.position, idealLocation, 0.01f);
transform.position = spot;
I have had good success using MoveTowards to have objects slowly go from where they are to where I want them to end up. The third parameter is how much to move and can be calculated using a desired speed * Time.DeltaTime to be more precise/move smoother than a constant like 0.01f does.