计算移动射手的射弹速度

问题描述 投票:0回答:0

我有一个游戏,我有一艘可以向任何方向射击的移动船。我必须拍摄站立或移动附近的物体。

问题是,我无法正确计算真正的射击方向。我必须找到一个方向,在应用船速后,我才能到达目标位置。

船拍功能:

public void shoot(vector3 direction)
{
   var p=  new projectile();
   p.velocity =ship.velocity + normalize(direction) * projectileSpeed;
   p.position=ship.position;
   world.add(p);
}

弹丸更新方法:

public void update()
{
    Position+=velocity * deltaTime;
}

那么必须传递给拍摄功能的真正方向是什么?

我尝试了以下计算:

1- direction=targetDirection - ship.velocity/projectileSpeed(未计算)

2- direction=vector3.reflect(ship.velocity + normalize(targetDirection) * projectileSpeed , targetDirection )(无效)

编辑1:

-所有速度(船,弹丸)都是矢量3.

-我不使用任何物理引擎,但我有 vector3 数学函数,如(归一化、投影、点、...)。

-Normalize mean vectorA/length(vectorA) 这意味着长度为 one 的向量

c# game-physics game-engine game-development
© www.soinside.com 2019 - 2024. All rights reserved.