当我向上或向下移动相机时,问题会发生 - 武器移出视图。我只调整了相对于摄像机的前向量和右向量调整了其位置,但似乎垂直运动没有正确考虑。
我尝试过的是:我试图根据相机的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();