如何将武器保持在摄像机的视野中,当 我正在雷利布(Raylib)进行第一人称射击游戏,我有一个工作系统来控制相机并在玩家面前绘制武器模型。但是,我在制作su上遇到了麻烦...

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

当我向上或向下移动相机时,问题会发生 - 武器移出视图。我只调整了相对于摄像机的前向量和右向量调整了其位置,但似乎垂直运动没有正确考虑。

我尝试过的是:

我试图根据相机的Y位置调整武器的Y位置,但是当我垂直移动相机时,它并不能解决问题。 我正在使用摄像头。要定位武器,但我不确定这是最好的方法。 问题:是否有更好的方法来处理摄像头定位,以便即使向上移动或向下移动时,武器也会留在相机的视野中?如何修改定位逻辑以确保武器始终留在相机前,无论垂直运动如何?

thy是更新的版本,当您使用自己的摄像机作为此类武器时,它运行良好。
// Begin 3D rendering for the main camera BeginMode3D(camera); // Draw the map model DrawModel(mapModel, {0, 0, 0}, 1.0f, WHITE); DrawGrid(200, 3); EndMode3D(); // Begin 3D rendering for the weapon camera BeginMode3D(weaponCamera); // Position the M4 model relative to the weapon camera Vector3 weaponPosition = {-0.5f, -1, -0.2}; // Adjust as needed for proper placement Vector3 rotationAxis = {0.0f, 1.0f, 0.0f}; // Rotation around Y axis float angle = 0.0f; // Static rotation for the weapon // Draw the weapon model DrawModelEx(m4Model, weaponPosition, rotationAxis, angle, {1.0f, 1.0f, 1.0f}, WHITE); EndMode3D();

c++ math camera game-development raylib
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.