返回介绍

Physics.SphereCastAll 球形投射列表

发布于 2019-12-18 15:38:16 字数 5395 浏览 1103 评论 0 收藏 0

JavaScript => public static function SphereCastAll(origin: Vector3, radius: float, direction: Vector3, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers): RaycastHit[];
C# => public static RaycastHit[] SphereCastAll(Vector3 origin, float radius, Vector3 direction, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);

Parameters 参数

originThe center of the sphere at the start of the sweep.
扫描开始的球形中心点。
radiusThe radius of the sphere.
球的半径。
directionThe direction into which to sweep the sphere.
球形扫描的方向
distanceThe length of the sweep.
扫描的长度。
layerMaskA Layer mask that is used to selectively ignore colliders when casting a capsule.
仅扫描指定层的碰撞器。

Returns 返回

RaycastHit[] An array of all colliders hit in the sweep.

返回扫描碰到的所有RaycastHit[]数组。

Description 描述

Like Physics.SphereCast, but this function will return all hits the sphere sweep intersects.

类似Physics.SphereCast,但是这个函数返回所有球形扫描到的碰撞信息。

Casts a sphere against all colliders in the scene and returns detailed information on each collider which was hit. This is useful when a Raycast does not give enough precision, because you want to find out if an object of a specific size, such as a character, will be able to move somewhere without colliding with anything on the way.

在场景中球形投射扫描所有碰撞器,并返回碰到的每一个碰撞器的细节信息。这对于Raycast无法满足需求时使用,比如你想找出指定大小的对象,比如角色能在某个地方移动,不与任何东西碰撞

Notes: SphereCastAll will not detect colliders for which the sphere overlaps the collider. The sphere cast does not work against colliders configured as triggers. If you move colliders from scripting or by animation, there needs to be at least one FixedUpdate executed so that the physics library can update it's data structures, before a sphere cast will hit the collider at it's new position.

注意,SphereCast不检测球体重叠的碰撞器。球形投射不检测触发器。如果从脚本或动画移动碰撞器,至少需要一个FixedUpdate来执行物理库更新数据结构,球形投射在它的新位置之前碰到碰撞器。

See Also: Physics.SphereCast, Physics.CapsuleCast, Physics.Raycast, Rigidbody.SweepTest.

C#:

using UnityEngine;
using System.Collections;
 
public class SphereCastTest : MonoBehaviour {
 
	void Update () {
		RaycastHit hit;
		var hits = Physics.SphereCastAll (transform.position,2,Vector3.forward,10);
		foreach (var item in hits) {
			Debug.Log (item.transform);
 
		}	
	}
}

JavaScript => public static function SphereCastAll(ray: Ray, radius: float, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers): RaycastHit[];
C# => public static RaycastHit[] SphereCastAll(Ray ray, float radius, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);

Parameters 参数

rayThe starting point and direction of the ray into which the sphere sweep is cast.
球形扫描的射线。
radiusThe radius of the sphere.
球的半径。
directionThe direction into which to sweep the sphere.
球形扫描的方向
distanceThe length of the sweep.
扫描的长度。
layerMaskA Layer mask that is used to selectively ignore colliders when casting a capsule.
仅扫描指定层的碰撞器。

Description 描述

Like Physics.SphereCast, but this function will return all hits the sphere sweep intersects.

类似Physics.SphereCast,但是这个函数返回所有球形扫描到的碰撞信息。

Physics

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文