【发布时间】:2020-02-11 12:20:23
【问题描述】:
这是我的特定于旋转事物的代码,由伪代码给出。
var rad = (targettransform.rotationEuler.y) * Math.PI / 180;
var difVec = targettransform.pos - othertransform.pos;
//the difVec.z which means radius
this._targetPos.z -= difVec.z * (1 - Math.cos(rad));
this._targetPos.x += difVec.z * Math.sin(rad);
this.transform.position = this._targetPos;
this.transform.lookAt(targettransform.position, Utils.UnitY);
上面的伪代码无非就是旋转,但是我不明白1 - Math.cos(rad)是做什么的,可能是相对于三角函数的一些推导。有人能详细解释一下这个数学吗?
编辑
对不起,我的错误,代码sn-p的主要目的是在x-z平面上将“_targetpos”偏移vec3(difVec.z * Math.sin(rad),0,this._targetPos.z)。我设法重写伪代码以使其有意义。看来sn-ps的代码只实现了保持相对距离和看目标的功能。
【问题讨论】:
标签: algorithm unity3d math 3d game-development