当前位置:网站首页>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 .
边栏推荐
- Establish cloth effect in 10 seconds
- AutoCAD - graphic input and output
- [groovy] closure (closure call | closure default parameter it | code example)
- Sqlserver stored procedures pass array parameters
- MySQL audit log archiving
- Variable category (automatic, static, register, external)
- Flutter tips: various fancy nesting of listview and pageview
- Leetcode 222 number of nodes of complete binary tree
- PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low
- AutoCAD - command repetition, undo and redo
猜你喜欢

The principle of attention mechanism and its application in seq2seq (bahadanau attention)
![[Business Research Report] top ten trends of science and technology and it in 2022 - with download link](/img/9f/4fc63fa7b0e9afc5dd638d4b599b2c.jpg)
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link

Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9

Introduce Hamming distance and calculation examples

AutoCAD - workspace settings

669. Prune binary search tree ●●

Create a pyGame window with a blue background
![[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)](/img/90/0cf08ae6fea61891e3e1fdf29d310c.jpg)
[groovy] closure (closure parameter binding | curry function | rcurry function | ncurry function | code example)

【Leetcode】1352. Product of the last K numbers

Séparation et combinaison de la construction du système qualité
随机推荐
Unity connects to the database
Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
Out and ref functions of unity
2020-10-27
49 pictures and 26 questions explain in detail what is WiFi?
775 Div.1 B. integral array mathematics
2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
Number theoretic function and its summation to be updated
Unity and database
JVM 原理和流程简介
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
Solution of circular dependency
Introduce Hamming distance and calculation examples
LeetCode之单词搜索(回溯法求解)
Unity synergy
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
C # perspective following
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem