当前位置:网站首页>Unity Vector3. Use and calculation principle of reflect
Unity Vector3. Use and calculation principle of reflect
2022-07-06 05:13:00 【Cuijiahao】
Calculate the reflection vector that the vector projects onto the object
Collision simulation :
public class test3 : MonoBehaviour
{
Vector3 dir;
Vector3 pos;
private void Start()
{
dir = transform.right;
pos = transform.position;
}
private void Update()
{
transform.position += dir * Time.deltaTime*4;
}
private void OnCollisionEnter2D(Collision2D collision)
{
Vector2 inDirection = (transform.position - pos).normalized;
Vector2 inNormal = collision.contacts[0].normal;
dir = Vector2.Reflect(inDirection, inNormal);
pos = transform.position;
}
}
Ray simulation :
void OnDrawGizmos()
{
#if UNITY_EDITOR
Color prevColor = Gizmos.color;
// Shoot a red ray from the origin to the right
Gizmos.color = Color.red;
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, Mathf.Infinity);
Gizmos.DrawLine(transform.position, hitInfo.point);
// The ray touches the normal of the colliding object
Gizmos.color = Color.green;
Gizmos.DrawLine(hitInfo.point, hitInfo.normal * 0.2f);
// Reflection
Gizmos.color = Color.blue;
Vector2 direction = Vector2.Reflect(hitInfo.point - (Vector2)transform.position, hitInfo.normal);
Gizmos.DrawLine(hitInfo.point, direction * 0.1f);
Gizmos.color = prevColor;
#endif
}
边栏推荐
- JS quick start (II)
- Yolov5 tensorrt acceleration
- Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
- C AES encrypts strings
- ORM aggregate query and native database operation
- Request (request object) and response (response object)
- The web project imported the MySQL driver jar package but failed to load it into the driver
- Huawei equipment is configured with OSPF and BFD linkage
- Force buckle 1189 Maximum number of "balloons"
- Postman前置脚本-全局变量和环境变量
猜你喜欢
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
[leetcode16] the sum of the nearest three numbers (double pointer)
Ora-01779: the column corresponding to the non key value saving table cannot be modified
JS quick start (II)
Crazy God said redis notes
yolov5 tensorrt加速
[leetcode] 18. Sum of four numbers
Imperial cms7.5 imitation "D9 download station" software application download website source code
Simple understanding of interpreters and compilers
随机推荐
Hyperledger Fabric2. Some basic concepts of X (1)
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
關於Unity Inspector上的一些常用技巧,一般用於編輯器擴展或者其他
[mask requirements of OSPF and Isis in multi access network]
ISP learning (2)
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
RT thread analysis log system RT_ Kprintf analysis
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
Pix2pix: image to image conversion using conditional countermeasure networks
[NOIP2009 普及组] 分数线划定
2021 robocom world robot developer competition - undergraduate group (semi-finals)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
趋势前沿 | 达摩院语音 AI 最新技术大全
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Postman管理测试用例
idea一键导包
Raspberry pie 3.5-inch white screen display connection
Why does MySQL need two-phase commit
Oracle query table index, unique constraint, field