博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity:计算两个物体(没有父子关系)的相对坐标
阅读量:3904 次
发布时间:2019-05-23

本文共 591 字,大约阅读时间需要 1 分钟。

Unity:计算两个物体(没有父子关系)的相对坐标

问题描述

计算Unity场景中物体B在物体A坐标系下的坐标,且两物体没有父子关系

实现方法

计算一个物体A的position相对于另一个物体B(origin)的坐标

private Vector3 GetRelativePosition(Transform origin, Vector3 position){
Vector3 distance = position - origin.position; Vector3 relativePosition = Vector3.zero; relativePosition.x = Vector3.Dot(distance, origin.right.normalized); relativePosition.y = Vector3.Dot(distance, origin.up.normalized); relativePosition.z = Vector3.Dot(distance, origin.forward.normalized); return relativePosition;}

实现原理

计算物体A在物体B下的坐标,即将物体B的坐标origin视为坐标原点,物体A的坐标即为(B-A)*B的归一化方向。

参考链接

转载地址:http://wloen.baihongyu.com/

你可能感兴趣的文章
What are some of the differences between using recursion to solve a problem versus using iteration?
查看>>
subsets
查看>>
Python Nested List Operation
查看>>
Python Binary Search
查看>>
How to append list to second list
查看>>
Write a program to print all permutations of a given string
查看>>
递归回溯
查看>>
穷举递归和回溯算法终结篇
查看>>
Exhaustive recursion and backtracking
查看>>
递归算法的时间复杂度终结篇
查看>>
全排列算法的递归与非递归实现
查看>>
Python Division and Remainders
查看>>
Python Division //
查看>>
BinarySearch
查看>>
二分查找(Binary Search)需要注意的问题,以及在数据库内核中的实现
查看>>
Arithmetic Progression
查看>>
Bisearch Summary
查看>>
Python - abs vs fabs
查看>>
Python integer ranges
查看>>
Python - Search Insert Position
查看>>