java 旋转方向_绕Z旋转方向

我有一架飞机 . 它在Y上旋转180度,他的位置是0,0,0,他面向X轴 . 这意味着我围绕Z(欧拉角)旋转它以改变它所面对的方向 . 我有 Cloud , Cloud 有一个运动脚本 . 我希望 Cloud 在与Y轴和X轴面对的方向相反的方向上移动 .

例如,当飞机的rotation.eulerAngles.Z = 0时, Cloud 应该全速移向负X.当rotation.eulerAngles.Z = 90时, Cloud 应该全速移向负Y.当rotation.eulerAngles.Z = 45 Cloud 应该以半速向负X移动,半速向负Y移动,依此类推 .

这里有两个插图,让您更容易想象:

这里是一张场景照片,让您更容易想象:

这个想法是为了创造飞机正在移动的错觉,实际上在这个场景中移动飞机会产生很多我真正不想处理的问题 .

当前的 Cloud 移动脚本:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class MoveCloud : MonoBehaviour

{

public float speed;

void Update()

{

var plane = GameObject.Find("plane");

var dir =(plane.transform.position - plane.transform.forward)*speed*Time.deltaTime ;

transform.position = new Vector3(transform.position.x + dir.x , transform.position.y + dir.y , transform.position.z);

if (transform.position.x < -140)Destroy(gameObject);

}

}

那你怎么解决这个问题呢?

团结一致 .

编辑:我认为在这里使用线性函数trigo可能会有所帮助,这是我的新代码:

public float speed;

void Update()

{

var plane = GameObject.Find("plane");//Get the airplane

var slope = Mathf.Tan(360 - plane.transform.rotation.eulerAngles.z);//Degrees to a slope (how much y it does in one x)

var y = 1*slope;//kinda the very definition of the slope...

var x = 1/slope;//math

transform.position += new Vector3(x,y,0)*Time.deltaTime*speed;//the 1 , 1 point of our linear function(our direction) * delta * speed

if (transform.position.x < -140)Destroy(gameObject);

}

目前, Cloud 层正在震动整个场景 . 有时候他们最终会走向正确的方向,但并不是空闲的 . 想在我的数学上得到第二个意见 .

我是如何解决这个问题的:我刚刚做到了

transform.position += GameObject.Find("plane").transform.right * Time.deltaTime * speed;

感谢PrinceOfRavens帮助我找到了这个

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值