Version: 2018.1 (switch to 2018.2b or 2017.4)
LanguageEnglish
• C#
• JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Vector3 Constructor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close
public Vector3(x: float, y: float, z: float)
public Vector3(float x, float y, float z);

Description

Creates a new vector with given x, y, z components.

`no example available in JavaScript`
```//Attach this script to a GameObject.
//Attach a Rigidbody component to the GameObject (Click Add Component button in the Inspector window and go to Physics<Rigidbody)
//This script moves a GameObject upwards using a Vector3
using UnityEngine;public class Vector3CtorExample : MonoBehaviour
{
Vector3 myVector;
Rigidbody m_Rigidbody;
float m_Speed = 2.0f;    void Start()
{
//Set the vector, which you use to move the RigidBody upwards straight away
myVector = new Vector3(0.0f, 1.0f, 0.0f);
//Fetch the RigidBody you attach to the GameObject
m_Rigidbody = GetComponent<Rigidbody>();
}    void Update()
{
//Move the RigidBody upwards at the speed you define
m_Rigidbody.velocity = myVector * m_Speed;
}
}
```

public Vector3(x: float, y: float)
public Vector3(float x, float y);

Description

Creates a new vector with given x, y components and sets `z` to zero.