while True:
enemy = hero.findNearestEnemy()
if enemy:
# 找到攻击的向量
raw = Math.atan2(enemy.pos.y - hero.pos.y, enemy.pos.x - hero.pos.x)
# 使用三角法找出弧度中的角度!
# 答案必须是度数!
# 用 (180 / Math.PI)把弧度变换成度数
degree = raw * (180 / Math.PI)
# 说出角度!
hero.say(degree)
这段代码演示了一个游戏AI的逻辑,它寻找最近的敌人,然后利用Math.atan2函数计算出从英雄到敌人的角度,并将弧度转换为度数。最后,AI会说出这个角度值。
while True:
enemy = hero.findNearestEnemy()
if enemy:
# 找到攻击的向量
raw = Math.atan2(enemy.pos.y - hero.pos.y, enemy.pos.x - hero.pos.x)
# 使用三角法找出弧度中的角度!
# 答案必须是度数!
# 用 (180 / Math.PI)把弧度变换成度数
degree = raw * (180 / Math.PI)
# 说出角度!
hero.say(degree)

被折叠的 条评论
为什么被折叠?