当前位置:网站首页>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 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis
- jmeter -- 分布式压测
- 2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
- 2021 electrician cup (the 12th "China Society of electrical engineering Cup" National Undergraduate electrician mathematical modeling) detailed ideas + codes + references
- Common database statements in unity
- PR first time
- The principle of attention mechanism and its application in seq2seq (bahadanau attention)
- Unity writes timetables (without UI)
- Research and forecast report on China's solution polymerized styrene butadiene rubber (SSBR) industry (2022 Edition)
- AutoCAD -- dimension break
猜你喜欢
2021-10-29
JVM 原理和流程简介
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
MySQL in-depth learning - index creation and deletion, index design principles, index failure scenarios, query optimization, index push down ICP
AutoCAD - full screen display
AutoCAD -- dimension break
[groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem
Introduction to JVM principle and process
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
随机推荐
Sqlserver stored procedures pass array parameters
MySQL audit log archiving
C iterator
3dsmax2018 common operations and some shortcut keys of editable polygons
669. 修剪二叉搜索树 ●●
775 Div.1 B. integral array mathematics
C # perspective following
2021 electrician Cup - high speed rail traction power supply system operation data analysis and equivalent modeling ideas + code
Special information | finance, accounting, audit - 22.1.23
Number theoretic function and its summation to be updated
China needle coke industry development research and investment value report (2022 Edition)
Personal required code
中国AS树脂市场调研与投资预测报告(2022版)
Wan broadband access technology V EPON Technology
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
中国金刚烷行业研究与投资预测报告(2022版)
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
AutoCAD - window zoom