当前位置:网站首页>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 .
边栏推荐
- 2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
- [groovy] closure (closure as function parameter | code example)
- [Business Research Report] top ten trends of science and technology and it in 2022 - with download link
- 質量體系建設之路的分分合合
- [ideas] 2021 may day mathematical modeling competition / May Day mathematical modeling ideas + references + codes
- 669. 修剪二叉搜索树 ●●
- 3dsmax common commands
- AutoCAD - scaling
- How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
- C4D simple cloth (version above R21)
猜你喜欢
[groovy] closure (closure call | closure default parameter it | code example)
"Measuring curve length" of CAD dream drawing
AutoCAD - workspace settings
Introduce Hamming distance and calculation examples
Is $20billion a little less? Cisco is interested in Splunk?
【Leetcode】1352. 最后 K 个数的乘积
AutoCAD - scaling
Redis 排查大 key 的4种方法,优化必备
SQL set operation
AutoCAD - window zoom
随机推荐
China needle coke industry development research and investment value report (2022 Edition)
How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
AutoCAD - full screen display
2021 electrician cup (the 12th "China Society of electrical engineering Cup" National Undergraduate electrician mathematical modeling) detailed ideas + codes + references
2021 huashubei mathematical modeling idea + reference + paper
3dsmax snaps to frozen objects
AutoCAD - command repetition, undo and redo
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
Wan broadband access technology V EPON Technology
Emlog blog theme template source code simple good-looking responsive
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
49 pictures and 26 questions explain in detail what is WiFi?
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link
AutoCAD - isometric annotation
C iterator
Séparation et combinaison de la construction du système qualité
AutoCAD - window zoom
Sixth note
Basic knowledge points of dictionary