[SOLVED] Am I getting blind, or is there a bug in this 'orbit-cam' setup?

please check this project for possible bugs … I can’t see what I am missing
https://playcanvas.com/editor/scene/1142210

  • camera will not orbit

I have just written this as [SOLVED], but this is not the whole truth (the project is still not working, and I will put it in the category of ‘some sort of server instability’ … maybe not repo-updates or backups - but still related to the actual harddisk-container: I moved the content and it worked [?] )

If somebody/some admins has/have the answer to the mystery - please let me know :-j

The reason it doesn’t work is because of this added code:

OrbitCamera.prototype.update = function(dt) {
    // Add inertia, if any
    var t = this.inertiaFactor === 0 ? 1 : Math.min(dt / this.inertiaFactor, 1);
    this._distance = pc.math.lerp(this._distance, this._targetDistance, t);
    this._yaw = pc.math.lerp(this._yaw, this._targetYaw, t);
    this._pitch = pc.math.lerp(this._pitch, this._targetPitch, t);

    if(this.vaultState === false){    this._updatePosition(); }
};

Specifically

    if(this.vaultState === false){    this._updatePosition(); }

this.vaultState is undefined so updatePosition is never called.

Refer to https://stackoverflow.com/questions/19277458/why-does-undefined-equals-false-return-false/19277873 on why.

ahh … ok - I did copy that orbit-script from a project to another with that alteration (was actually looking for that to be sure I did not include that vaultstate) … guess I missed it; only one line :-/

So in short in relation to: https://stackoverflow.com/questions/19277458/why-does-undefined-equals-false-return-false/19277873

  • it sort of displays a ‘devtools hole’, that does not give a err msg in console?
    [in such case I will take it with me on forward, in my way of debugging]

It’s because it isn’t an error. It’s defined behaviour in JS.

This is where debugging techniques and processes are useful to finding code logic issues like this.

1 Like

related to working with try/catch (compile or not compile)?
If I wrote:

if(this.vaultState === false){ this._updatePosition(); } console.log(this.vaultState);

  • I would have solved my ‘mystery’, whereas a ‘comparement’ that does not turn true anyway, will not compile?

Using a try / catch wouldn’t change anything as no exception is thrown.

That would run without code errors and print out undefined in the console.log.

The way I debugged it was:

  • Removing all files but the the orbit camera and the input
  • Using the devtools to breakpoint where distance on the orbit camera was being changed
  • Checked which code was responsible for using distance to position the camera (adding a breakpoint in the function showed the code not executing)
  • Checking where that function was called (if(this.vaultState === false){ this._updatePosition(); } )
  • Checking where the property this.vaultState value was set (it wasn’t so therefore is undefined and this if statement would evaluate to false)
1 Like