S
S
s2sk13372017-11-08 06:11:02
C++ / C#
s2sk1337, 2017-11-08 06:11:02

How to fix an error in a formula?

Hello.
I can't fix the bug with the camera in the game. For some reason, the lower the camera looks, the faster it moves. That is,
PZZNtHw.png
Green - where I'm looking
Blue - where I'm moving
Red - the camera
And the lower I look - the faster the camera starts to accelerate, and when I look at the floor at all - it moves away very far in one movement.
The actual code is

if (ЕСЛИ КНОПКА W ЗАЖАТА) // Вперед
  {
    MainRenderGraphics.pos_camera[0] -= sin(MainRenderGraphics.pos_camera_at[0] / 180 * PI) * 0.5;
    MainRenderGraphics.pos_camera[1] += tan(MainRenderGraphics.pos_camera_at[1] / 180 * PI) * 0.5;
    MainRenderGraphics.pos_camera[2] -= cos(MainRenderGraphics.pos_camera_at[0] / 180 * PI) * 0.5;
  }

  if (ЕСЛИ КНОПКА S НАЖАТА) // (назад)
  {
    MainRenderGraphics.pos_camera[0] += sin(MainRenderGraphics.pos_camera_at[0] / 180 * PI) * 0.5;
    MainRenderGraphics.pos_camera[1] -= tan(MainRenderGraphics.pos_camera_at[1] / 180 * PI) * 0.5;
    MainRenderGraphics.pos_camera[2] += cos(MainRenderGraphics.pos_camera_at[0] / 180 * PI) * 0.5;
  }

pos_camera - coordinates of the camera position
pos_camera_at - where it looks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2017-11-08
@jcmvbkbc

Why take trigonometric functions from view direction components? If you need to move in the direction of gaze, you should add to the camera position the product of the velocity and the normalized vector of the gaze direction and the duration of one frame.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question