# Updating Position Through Script Code

## Overview

When the game is running, you will not be able to move around objects as you can within the editor, so one way to change an object's position is by updating the object's position coordinates.

The position is a vector3 variable with read-only parts, so you cannot update just one axis at a time through transform.position.y = 1.0F or something similar. You need to use the keyword new followed by a complete Vector3. Here's an example:

```csharp
// Moves the object directly to (1,0,0)
transform.postion = new Vector3(1.0F, 0, 0);
```

Here, the object moves to (1,0,0). If it starts at (0,0,0), it appears to jump to the right in one frame and stays there until moved again.

## Moving Objects by Updating the Position Smoothly Through Code

{% hint style="info" %}
Moving objects this way is generally OK, but you might run into issues if you use it for player movement. For those situations, use Transform.Translate() instead.
{% endhint %}

**Example codes:**

* *Each example should be placed within the Update() or FixedUpdate() function so that it runs once per frame*
* *Each example moves the object it is attached to in the positive direction of the x-axis (right)*

```csharp
// Moves the object continuously along the x-axis
transform.postion += new Vector3(1.0F, 0, 0) * Time.deltaTime;
```

The code above:

1. Accesses the object's transform and then its position
2. Uses the += shortcut to add values to itself
3. *new Vector3(float x, float y, float z)* is a way to tell it to add the matching variables
4. *Time.deltaTime* adjusts for varying computer [speeds](https://hopemoore.gitbook.io/unity-basics/translate-rotate-and-scale/controlling-speed)

```csharp
// Moves the object continuously along the x-axis
transform.postion += Vector3.right * Time.deltaTime;
```

The code above:

1. Accesses the object's transform and then its position
2. Uses the += shortcut to add values to itself
3. *Vector3.right* is a [shortcut](https://hopemoore.gitbook.io/unity-basics/translate-rotate-and-scale/handy-transform-shortcuts) for Vector3(1.0F, 0.0F, 0.0F);
4. *Time.deltaTime* adjusts for varying computer speeds


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hopemoore.gitbook.io/unity-basics/translate-rotate-and-scale/translate/updating-position.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
