Home Game Development 3d – Walking round a sphere (planet)

### 3d – Walking round a sphere (planet)

Yet one other query, about strolling across the sphere. I need to say, I’m new to 3D programming..
I’ve researched this problem so much, however I’m unable to get to the answer. I’m utilizing THREE.js.
I can stroll across the sphere, however on some angles, the path converges on to the south pole… I’ve made a codepen, the place you possibly can play with it –
https://codepen.io/LeQwasd/pen/RwMmrmg (Controls: WASD for motion, QE for jaw)

The problem I’m having – is (apparently) – furry ball downside. I discovered this: How do I repair my planet-facing digicam? – I’ve studied it, however I’m unable to decipher the given reply… I’m not certain, apply it inside THREE.js. I’ve discovered the “poleDirection” vector.. (purple arrow within the codepen)..

I Have additionally seemed into this reply – Walking on a sphere

This behaves properly, however this resolution is just not what I need..

The related code, I’ve seems like this:

``````    replace(delta: quantity): void {
// Gather inputs
const path = new Vector3();
if (this.ok.isPressed("w")) {
path.z -= 2;
}
if (this.ok.isPressed("s")) {
path.z += 2;
}
if (this.ok.isPressed("a")) {
path.x -= 2;
}
if (this.ok.isPressed("d")) {
path.x += 2;
}
// Gather rotation
if (this.ok.isPressed("q")) {
this.angle += Math.PI / 180;
}
if (this.ok.isPressed("e")) {
this.angle -= Math.PI / 180;
}

const orientation = new Quaternion()
// Get the rotation so the item aligns with native up
.setFromUnitVectors(this.up, this.\$UP)
// And apply jaw
.multiply(new Quaternion().setFromAxisAngle(this.up, this.angle));

// Point enter velocity within the path
path.applyQuaternion(orientation);
// calculate new place

// Set place
this.place.copy(newPosition);
// Set orientation
this.quaternion.copy(orientation);

this._up.setDirection(this.\$UP);
this._right.setDirection(this.\$RIGHT);

// get native up
this.\$UP.copy(this.place).normalize();
this.\$RIGHT.set(1, 0, 0).applyQuaternion(this.quaternion);

updateChildren(this, delta);
}
``````