In this reworked example there is a host and client html pages, client script can be run https://verudalabs.dyndns.org/testgame_client.html , keyboard events in client page are sent via websockets to _host.html
document.addEventListener( 'keydown', ( event ) => {
let data = {}
data.event = "keydown"
data.event_code = event.code
data._forwardVector = getForwardVector()
data._sideVector = getSideVector()
data.playerDirection = {x:playerDirection.x,y:playerDirection.y,z:playerDirection.z}
websock.send('event:'+JSON.stringify(data))
} );
host.html script can be seen at https://verudalabs.dyndns.org/testgame_host.html but to rerun it I need to manually restart websockets worker.
//in host script event gets processed by following code:
lines 203 - 221
//so both _forwardVector and _sideVector get assigned to the player
//_self is just safe instance method for assuring setting properties to proper player
//and finally in the host script keydowns get processed by controls function but _forwardVector is same as _sideVector and keyW and keyS work same as keyA and keyD
lines 499-538 of host.html is the controls update function for each player.
How to make them go forwards/backwards?