当前位置:网站首页>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 .
边栏推荐
- Unity get component
- C # perspective following
- #775 Div.1 C. Tyler and Strings 组合数学
- 数论函数及其求和 待更新
- Unity intelligent NPC production -- pre judgment walking (method 1)
- 2021-10-29
- 中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
- Unity writes timetables (without UI)
- Out and ref functions of unity
- Wan broadband access technology V EPON Technology
猜你喜欢
Solutions and answers for the 2021 Shenzhen cup
Recherche de mots pour leetcode (solution rétrospective)
Number theoretic function and its summation to be updated
Flutter tips: various fancy nesting of listview and pageview
数论函数及其求和 待更新
Introduction to JVM principle and process
【acwing】836. Merge sets
AutoCAD - set layer
2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis
PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
随机推荐
Establish cloth effect in 10 seconds
AutoCAD - Document Management
JVM 原理和流程简介
Variable category (automatic, static, register, external)
Emlog blog theme template source code simple good-looking responsive
On-off and on-off of quality system construction
An article takes you to thoroughly understand descriptors
質量體系建設之路的分分合合
猿人学第一题
Introduction to JVM principle and process
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
PR first time
Introduce Hamming distance and calculation examples
[groovy] closure (closure call | closure default parameter it | code example)
Create a pyGame window with a blue background
【acwing】837. Number of connected block points
Interface joint commissioning test script optimization V5.0 (end)
LeetCode之单词搜索(回溯法求解)
2021 electrician cup idea + code - photovoltaic building integration plate index development trend analysis and prediction: prediction planning issues
SQLServer 存储过程传递数组参数