1
\$\begingroup\$

How can I transform.Translate (Vector3.up * Time.deltaTime * 2); a GameObject for 10 units? I mean only make it go up 10 units (10 y units).

\$\endgroup\$
1
\$\begingroup\$
you can move a object 10 units up using
transform.Translate(0.0f, 10.0f, 0.0f);

many ways to implement but I wrote this out to get you started

float yPos;
float yEnd;
void Start () {
    yPos = this.transform.position.y;
    yEnd = yPos + 10;     
}
void Update () {
    if(yPos < yEnd)
    {
        yPos = this.transform.position.y;
        transform.Translate(0.0f, 10.0f * Time.deltaTime, 0.0f);
    } 
}   
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Set a variable as your target destination before you start moving, then use Vector3.MoveTowards to gradually move towards your destination.

You'll also want to specify a movement speed.

Vector3 targetPosition = transform.position + new Vector3(0, 10, 0);
float movementSpeed = 1f;

void Move () {
    transform.position = Vector3.MoveTowards(transform.position, targetPosition, movementSpeed * Time.deltaTime);
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy