A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.unity3d.com/Manual/../ScriptReference/Transform.GetPositionAndRotation.html below:

Unity - Scripting API: Transform.GetPositionAndRotation

Transform.GetPositionAndRotation 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 Your name Your email Suggestion*

Cancel

Switch to Manual Declaration

public void

GetPositionAndRotation

(out

Vector3 position

, out

Quaternion rotation

);

Parameters Parameter Description position Out parameter that will receive the position of the transform in world space. rotation Out parameter that will receive the rotation of the transform in world space. Description

Updates the value of the out parameters position and rotation with the transform's current position and rotation in world space (that is, relative to the scene's origin coordinates).

Note: When getting both the position and rotation of a Transform, calling this method is more efficient than querying to Transform.position and Transform.rotation individually.

The typical usage for this method is to retrieve a transform's position and rotation in world space, to either display them or evaluate them. For example:

transform.GetPositionAndRotation(out Vector3 position, out Quaternion rotation)

The following example logs the position and rotation of a GameObject's Transform in world space.

using UnityEngine;

// Attach this script to a GameObject as a component. public class GetPositionAndRotationExample : MonoBehaviour { void Start() { // transform refers to the Transform of the GameObject this script is attached to. transform.GetPositionAndRotation(out Vector3 position, out Quaternion rotation);

// We will convert the rotation Quaternion to Euler angles for readability. Debug.Log($"{name} is located at {position}, and has the rotation {rotation.eulerAngles}"); } }

Additional resources: Quaternion, Vector3.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4