0
\$\begingroup\$

Duck on a sphere 'world'

I'm trying to make a rubber duck move along the surface of a round 'world' - I should be able to rotate the duck on it's local Y axis and then move the duck forward, with the duck following the surface of the world.

Effectively these are tank controls for a duck, on the surface of a sphere.

I'm able to spin the duck on it's Y axis when it's at the top or bottom of the world, then push it forward on the nested X axis.

The problem is that when the duck is away from the poles, pushing left and right cause the duck to orbit the world instead of turn on it's local Y axis (and then move forward (around the globe) relative to the duck).

I'm currently attempting to apply rotations to the duck before translating it with the code pictured, but I don't seem to have any change to my undesired behaviour... =/

BeginMode3D(camera);

DrawModel(world, worldPos, 1.0f, WHITE);    // Draw world

rlPushMatrix(); // DUCK MATRIX Y

rlRotatef(duckOrbitRotationY, 0.0f, 1.0f, 0.0f);
// rlTranslatef(0.0f, 1.0f, 0.0f); // Swapped the order of the rotation, then translate

// rlPopMatrix();

rlPushMatrix(); // DUCK MATRIX X

rlRotatef(duckOrbitRotationX, 1.0f, 0.0f, 0.0f);

rlPushMatrix(); // DUCK MATRIX Z

rlTranslatef(0.0f, 1.0f, 0.0f);
//rlRotatef(duckOrbitRotationY, 0.0f, 1.0f, 0.0f);

// rlRotatef(duckOrbitRotationZ, 0.0f, 0.0f, 1.0f);

DrawModel(model, duckPos, 1.0f, WHITE);    // Draw duck

rlPopMatrix();

rlPopMatrix();

rlPopMatrix(); // END DUCK MATRIX
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Please share code as formatted text, not as images. You can visit the help center for formatting support. You may also be interested in How can I fix my planet-facing camera, which involves similar control system math around a sphere. \$\endgroup\$ Commented Jan 26 at 1:00
  • \$\begingroup\$ Replaced image with code quote. Will investigate the planet-facing camera link. Somewhat new to using C++/Raylib, any help appreciated. \$\endgroup\$ Commented Jan 27 at 0:07

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.