当前位置:网站首页>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 .
边栏推荐
- AutoCAD - stretching
- Number theoretic function and its summation to be updated
- 【Leetcode】1352. Product of the last K numbers
- China as resin Market Research and investment forecast report (2022 Edition)
- 质量体系建设之路的分分合合
- China needle coke industry development research and investment value report (2022 Edition)
- Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
- MySQL audit log archiving
- PR first time
- Redis 排查大 key 的4种方法,优化必备
猜你喜欢
![[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)](/img/1b/1fa2ebc9a6c5d271c9b39f5e508fb0.jpg)
[groovy] closure (Introduction to closure class closure | closure parametertypes and maximumnumberofparameters member usage)

PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低

【acwing】528. cheese

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

AutoCAD - stretching

PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low

AutoCAD - Center zoom

C4D simple cloth (version above R21)

【acwing】240. food chain

669. 修剪二叉搜索树 ●●
随机推荐
2020-10-27
3dsmax common commands
SQL set operation
AutoCAD - scaling
AutoCAD - isometric annotation
AutoCAD - command repetition, undo and redo
2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
XSS injection
Rip notes [rip message security authentication, increase of rip interface measurement]
Minor spanning tree
The difference between heap and stack
LeetCode之单词搜索(回溯法求解)
中国聚氨酯硬泡市场调研与投资预测报告(2022版)
On-off and on-off of quality system construction
JMeter -- distributed pressure measurement
669. Prune binary search tree ●●
Unity parallax infinite scrolling background
AutoCAD - full screen display
Panel panel of UI
用 Jmeter 工具做个小型压力测试