GetInstanceTransform(NavNode, out Vector3, out Quaternion)
Retrieves the position and rotation of the NavMesh surface that contains the specified NavMesh node.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
GetInstanceTransform(NavNode, Vector3, Quaternion)
public readonly void GetInstanceTransform(NavNode node, out Vector3 position, out Quaternion rotation)
Parameters
The NavMesh node whose owner's transform to retrieve.
Outputs the world position of the NavMesh surface that owns the specified node.
This is a zero vector when the NavMesh node is a NavMesh Link.
Outputs the world rotation of the NavMesh surface that owns the specified node.
This is Quaternion.identity when the NavMesh node is a NavMesh Link.
Remarks
Unity defines the transform of a NavMeshData surface from the and values that you declare when you bake the surface with BuildNavMeshData, or as part of a NavMesh Surface, or when you explicitly set the values for NavMeshData.position and NavMeshData.rotation.
positionrotationYou can also specify custom transforms for NavMeshDataInstances when you create them, by passing explicit and values to the NavMesh.AddNavMeshData method.
positionrotationImportant: This method doesn't return the position and orientation of a single NavMesh polygon. It returns the position of the surface that owns the polygon.
Note: This method returns zero and identity instead of the actual transform for NavMesh Links that you instantiate with a call to NavMesh.AddLink.
Additional Resources: NavWorld.GetNodeType
Examples
using UnityEngine;using Unity.AI.Navigation.LowLevel;public class InstanceTransformExample : MonoBehaviour{ void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(transform.position, Vector3.one, 0); if (!world.IsValid(location)) return; world.GetInstanceTransform(location.node, out Vector3 surfacePosition, out Quaternion surfaceRotation); Debug.DrawRay(surfacePosition, surfaceRotation * Vector3.up, Color.yellow); }}