Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PhysicsQuery.WorldCastResult

The results from performing any Cast query against the PhysicsWorld.
Read time 2 minutesLast updated 13 days ago

Definition

public readonly struct PhysicsQuery.WorldCastResult : IEquatable<PhysicsQuery.WorldCastResult>

Remarks

Use PhysicsWorld.CastGeometry or PhysicsWorld.CastRay to check whether a shape or ray will intersect other shapes as it moves through the world, for example to predict a collision before it happens.

Examples

// Check whether a small falling circle will collide with objects underneath it.using UnityEngine;using Unity.U2D.Physics;using Unity.Collections;public class CastGeometryExample : MonoBehaviour{ private PhysicsWorld world; void Start() { world = PhysicsWorld.defaultWorld; // Create a small falling circle. CircleGeometry object1Geometry = CircleGeometry.Create(0.5f, new Vector2(0.5f, 8f)); PhysicsBody object1 = world.CreateBody(new PhysicsBodyDefinition { position = object1Geometry.center, type = PhysicsBody.BodyType.Dynamic }); object1.CreateShape(object1Geometry); // Set the translation and filter for the cast. Vector2 translation = new Vector2(0, -10f); PhysicsQuery.QueryFilter filter = new PhysicsQuery.QueryFilter(); // Cast the circle geometry through the world. // Use "using" to automatically dispose of the NativeArray once it goes out of scope. using NativeArray<PhysicsQuery.WorldCastResult> results = world.CastGeometry(object1Geometry, translation, filter, PhysicsQuery.WorldCastMode.Closest, Allocator.Temp); if (results.Length > 0) { Debug.Log("Collision will occur!"); } }}

Properties

Property

Description

fractionThe fraction of the query cast distance the shape would move to the point of detection, in the range [0, 1].
isValidCheck if the result is valid.
normalThe surface normal at the point of contact. In all non-overlapped cases, this will be a unit-normal. If there was an initial overlap, the normal will be zero (degenerate) along with the _fraction being zero and _point being an arbitrary point in the overlapped region. See _point.
pointThe point of contact.
shapeThe shape that was detected by the cast.

Structs

Struct

Description

PhysicsQuery.WorldCastResult.SortAscendingOrderAscending distance sort comparer.