[SOLVED] Mouse enabled/released over html

Hello Guys!

I having some trouble finding a proper solution for enable / disable the mouse with a trigger/collision. I have a html overlay to the canvas, and need the mouse to be release for use on collision. Is this possible?

Kind regards.

Hi @Anders_Juul_Jorgense,

You can release the mouse pointer at any instant using the following method:

this.app.mouse.disablePointerLock();

For example you can call it when your player enters the trigger or when enabling the HTML overlay, so the mouse pointer shows.

1 Like

Thanks a lot @Leonidas.

Okay, I have this script:

   var EwWNMOK = pc.createScript('EwWNMOK');

EwWNMOK.attributes.add('css', {type: 'asset', assetType:'css', title: 'CSS'});
EwWNMOK.attributes.add('html', {type: 'asset', assetType:'html', title: 'Pracka-HTML'});


EwWNMOK.prototype.initialize = function () {
	var style = document.createElement('style');

	document.head.appendChild(style);
	style.innerHTML = this.css.resource || '';

	this.div = document.createElement('div');
	this.div.classList.add('container');
	this.div.innerHTML = this.html.resource || '';

//  document.body.appendChild(this.div);
	var isEnabled = false;
    
	this.app.on('WNMhtml:enable', function() {

		if( isEnabled === false ){
			document.body.appendChild(this.div);
			isEnabled = true;
		}
	}, this);

	this.app.on('WNMhtml:disable', function() {

		if( isEnabled === true ){
			document.body.removeChild(this.div);
			isEnabled = false;
		}
	}, this);



};

How would i place it in here?

Reading your code, I imagine you’d put it here?

	this.app.on('WNMhtml:enable', function() {

        this.app.mouse.disablePointerLock();

		if( isEnabled === false ){
			document.body.appendChild(this.div);
			isEnabled = true;
		}
	}, this);
2 Likes

YES perfekt! thank you!