计算旋转的最短路径,向右还是向左? [英] Calculate the shortest way to rotate, right or left?

查看:104
本文介绍了计算旋转的最短路径,向右还是向左?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个简单的2D动作游戏制作一个简单的电脑游戏。它假设转向我并开枪,但我无法弄清楚如何计算最短路径......如果它想要射击并杀死我,它应该向左转吗?P?

Im making a simple computerplayer to my simple 2d action game. it suppose to turn towards me and shoot, but i cant figure out how to calc the shortest path... should it turn left of right if it want to shoot and kill me :P ?

我有两个角度:cpu_facing(cpu面向的方向)和player_degree(当cpu位于中心时计算的角度)。

Ive got two angles: cpu_facing (direction the cpu is facing) and player_degree (the angle calculated when cpu is in the center).

(即时工作)有度,不喜欢radian:P)

(im working with degrees, dont like radian :P)

任何人都是用javascript完成的吗?

Anyone done this in javascript?

推荐答案

(cpu_facing-player_degree+360)%360>180




  • false :转向否定方向

  • true :转向正方向

    • false: turn in the negative direction
    • true: turn in the positive direction
    • 这篇关于计算旋转的最短路径,向右还是向左?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆