Keyboard Interaction of Objects in View

Holy crap, thank you so much @Leonidas!

The script works as expected, and I really appreciate your help. I see now how the placement of the rotate command impacts it’s behavior. One question at an engine level, multiplying the rotation by dt, appears to be the determining factor in keeping the velocity flat. Why is that? Now I know it has to be done, but understanding the concept I’m sure would go a long way for me. Does multiplying by dt take into account real time and not necessarily just raw frame production?

2 Likes

The reason is that this code moves the object every frame, but the time it takes to generate each frame isn’t constant. Sometimes it’s longer other times it’s shorter.

So if you translate your object by a constant 1 unit every frame, it’s velocity won’t be constant and the animation won’t be smooth.

The dt variable is the time it took to generate this frame since the previous one, so by multiplying our translation with it ensures that the amount the object moves each frame is constant.

1 Like

Posting for reference the proposed way on doing a visibility check on a mesh instance:

var MeshVisScript = pc.createScript('meshVisScript');

MeshVisScript.prototype.initialize = function() {
 
    this.app.scene.layers.getLayerByName("World").onPostCull = (cameraIndex) => {
        var entity = this.app.root.findByName("Box");
        var meshInstance = entity.model.model.meshInstances[0];
        console.log("visible: " + meshInstance.visibleThisFrame);
    }    
};
2 Likes