当前位置:网站首页>Unity check whether the two objects have obstacles by ray
Unity check whether the two objects have obstacles by ray
2022-07-05 04:55:00 【yoyoHm】
Function description :
Ray(Vector3 origin, Vector3 direction )
Ray( The starting point of the ray , The direction of the ray (Unity 3D It will automatically normalize units ))
This overloaded function uses existing rays Ray As parameters and get collision information RaycastHit.
Raycast(Ray ray, RaycastHit hitInfo, float distance = Mathf.Infinity( Infinite ), intlayerMask = DefaultRaycastLayers);
Raycast( ray , Collision information , distance , Ray collision level );
The direction of the ray : Find a vector by subtracting two points
// Save collision information
RaycastHit m_hit;
Ray ray = new Ray(transform.position ,playerTransform.transform.position-transform.position);
if(Physics.Raycast(ray, out m_hit, Vector3.Distance(transform.position, playerTransform.position)))
{
if (m_hit.transform.tag == "Wall" )
{
Debug.Log(" Name of collision object "+m_hit.transform.name);
Debug.DrawLine(transform.position ,playerTransform.transform.position,Color.red);
}
}

Add in case of subsequent use :
X-ray penetration testing , Check that multiple rays collide with objects
Physics.RaycastAll: This function is related to Physics.Raycast The difference is that it can detect multiple objects touched by rays . The return value is an array of collision information , Whether or not you touch an object , Arrays are not null , If you don't touch the object, the length of the array will be 0.
Physics.RaycastNonAlloc: This function is related to Physics.RaycastAll similar , It is also used to detect objects touched by rays . The difference lies in the return value ,Physics.RaycastAll The return value is an integer , Is the number of objects hit by rays .
边栏推荐
- 54. Spiral matrix & 59 Spiral matrix II ●●
- Fluent objects and lists
- 计组笔记(1)——校验码、原补码乘除计算、浮点数计算
- C iterator
- AutoCAD - full screen display
- Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
- AutoCAD - lengthening
- 54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
- Function template
- Unity synergy
猜你喜欢

Redis has four methods for checking big keys, which are necessary for optimization

Thinking of 2022 American College Students' mathematical modeling competition

Redis 排查大 key 的4种方法,优化必备

Minor spanning tree

JVM 原理和流程简介

2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas

LeetCode之单词搜索(回溯法求解)

On-off and on-off of quality system construction

AutoCAD - lengthening

Solutions and answers for the 2021 Shenzhen cup
随机推荐
AutoCAD - Document Management
Sqlserver stored procedures pass array parameters
中国艾草行业研究与投资前景预测报告(2022版)
669. 修剪二叉搜索树 ●●
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
This article is good
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
Emlog blog theme template source code simple good-looking responsive
中国聚氨酯硬泡市场调研与投资预测报告(2022版)
AutoCAD - full screen display
flutter 对象和列表
数论函数及其求和 待更新
3dsmax common commands
SQL set operation
2021 electrician Cup - high speed rail traction power supply system operation data analysis and equivalent modeling ideas + code
Unity3d learning notes
AutoCAD - Center zoom
775 Div.1 B. integral array mathematics
Basic knowledge points of dictionary
"Measuring curve length" of CAD dream drawing