-1
\$\begingroup\$

I wrote an object, in Game Maker. My problem is that the camera appears to be nonexistent. It does not follow the player, and from the perspective it displays on the screen, I believe I simply do not have a camera.


This is my Step event:

right = keyboard_check(vk_right);
left = keyboard_check(vk_left);
forward = keyboard_check(vk_up);
back = keyboard_check(vk_down);

if (jump==0 && keyboard_check(vk_space))
{
    sound_play(snd_jump);
    x += 3 * unitZ_x;
    y += 3 * unitZ_y;
    z += 3 * unitZ_z;
    jump = 1;
    canjump = 4;
}

canjump -= 0.5;
x += unitZ_x * canjump;
y += unitZ_y * canjump;
z += unitZ_z * canjump;

if (canjump < -8)
{
    canjump = -8;
    falling = 1;
}

currentRadius = sqrt((x - centerX) * (x - centerX) 
        + (y - centerY) * (y - centerY) + (z - centerZ) * (z - centerZ));

if (currentRadius < radius)
{
    x -= (currentRadius - radius) * unitZ_x;
    y -= (currentRadius - radius) * unitZ_y;
    z -= (currentRadius - radius) * unitZ_z;
    currentRadius = sqrt((x - centerX) * (x - centerX)
            + (y - centerY) * (y - centerY) + (z - centerZ) * (z - centerZ));
    jump = 0;
    falling = 0;
    canjump = 0;
}

if ((right==1) || (left==1))
{
    x += (right - left) * 4 * unitX_x;
    y += (right - left) * 4 * unitX_y;
    z += (right - left) * 4 * unitX_z;

    distance = sqrt((x - centerX) * (x - centerX) 
            + (y - centerY) * (y - centerY) + (z - centerZ) * (z - centerZ));

    unitZ_x = (x-centerX) / distance;
    unitZ_y = (y-centerY) / distance;
    unitZ_z = (z-centerZ) / distance;

    x -= (distance - currentRadius) * unitZ_x;
    y -= (distance - currentRadius) * unitZ_y;
    z -= (distance - currentRadius) * unitZ_z;

    unitX_x = unitY_y * unitZ_z - unitY_z * unitZ_y;
    unitX_y = unitY_z * unitZ_x - unitY_x * unitZ_z;
    unitX_z = unitY_x * unitZ_y - unitY_y * unitZ_x;
}

currentRadius = sqrt((x - centerX) * (x - centerX) 
        + (y - centerY) * (y - centerY) + (z - centerZ) * (z - centerZ));

if ((forward==1) || (back==1))
{
    x += (forward - back)*4*unitY_x;
    y += (forward - back)*4*unitY_y;
    z += (forward - back)*4*unitY_z;

    distance = sqrt((x - centerX) * (x - centerX) 
            + (y - centerY) * (y - centerY) + (z - centerZ) * (z - centerZ));

    unitZ_x = (x - centerX) / distance;
    unitZ_y = (y - centerY) / distance;
    unitZ_z = (z - centerZ) / distance;


    x -= (distance - currentRadius) * unitZ_x;
    y -= (distance - currentRadius) * unitZ_y;
    z -= (distance - currentRadius) * unitZ_z;

    unitY_x = unitZ_y * unitX_z - unitZ_z * unitX_y;
    unitY_y = unitZ_z * unitX_x - unitZ_x * unitX_z;
    unitY_z = unitZ_x * unitX_y - unitZ_y * unitX_x;
}

This is my Draw event:

  d3d_draw_ellipsoid(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1, 0, 1, 1, 60);
  d3d_set_projection_perspective(0, 0, 640, 480, 0);
  d3d_set_projection(x - 4 * unitY_x, y - 4 * unitY_y, z - 4 * unitY_z, unitY_x,
          unitY_y, unitY_z, unitZ_x, unitZ_y, unitZ_z);

Does anyone know what I have done wrong? I think it is a simple 3D camera glitch, but I have never made a camera before (in anything for that matter) so chances are it is something really basic.

\$\endgroup\$
  • 1
    \$\begingroup\$ yet again another question down-voted with no context! \$\endgroup\$ – Ryan white Nov 1 '16 at 9:19
  • \$\begingroup\$ @Ryanwhite i know, right? I don't mind down votes but if it's continuing repeatedly at least take a minute to say why. :p \$\endgroup\$ – user64742 Jan 6 '17 at 19:19
1
\$\begingroup\$

Your problem is that 3D objects in game maker are drawn by order of their depth, with highest depth taking priority. Each step, any view transformations (including the camera) are reset. Try making the depth a really large number (say 1000000000) and see what happens.

Also, the only other issue I see is that the second vector in d3d_set_projection() is supposed to be a position vector of where you are looking, not a direction vector, but I'm sure you can figure that out.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.