ActionManager not catching all double clicks

Hail!

I was perusing the site and found the documentation on the action manager. So I created this playground to swap the camera target on double click.

It seems to work ok but i noticed that when I change the camera target I sometimes have to double click more than once to change target. Sometimes, it just stops working. Is that because I’m trying to swap too fast?

I have a playground for it, but its not saving. Saying the code is too long. I’ll put it up as soon as it lets me, but here’s the code anyway:

var createScene = function() {
	var scene = new BABYLON.Scene(engine);
	scene.clearColor = new BABYLON.Color3(0.8, 0.8, 0.8);
    scene.checkCollisions = true;
    scene.collisionsEnabled = true;
	//var camera = new BABYLON.ArcRotateCamera("camera1", new BABYLON.Vector3(0, 0, -30), scene);
    var camera = new BABYLON.ArcRotateCamera("camera1", 0, 0, 10, new BABYLON.Vector3(0, 0, 0), scene);
	camera.attachControl(canvas, true);
    //camera.ellipsoid = new BABYLON.Vector3(0, 0, 0);
    camera.checkCollisions = true;
    camera.applyGravity = true;
	camera.speed = 1;
    camera.layerMask = 2;

	var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 1), scene);
	light.intensity = .5;
 

	var mesh = BABYLON.Mesh.CreateBox("box1", 2.0, scene);
     
    mesh.material =  new BABYLON.StandardMaterial('texture1', scene);
    mesh.material.diffuseColor = new BABYLON.Color3(1, 0, 0);	  
	mesh.isPickable = true;

    camera.setTarget(mesh.position);
    var b1 = BABYLON.Mesh.CreateBox("b1", 2, scene);
    var b2 = BABYLON.Mesh.CreateBox("b2", 2, scene);
    var b3 = BABYLON.Mesh.CreateBox("b3", 2, scene);
    var b4 = BABYLON.Mesh.CreateBox("b4", 2, scene);

    // Move the sphere upward 1/2 its height
    b1.position.x = -8;
    b2.position.x = 4;
    b3.position.x = 8;
    b4.position.x = -4;

    b1.isPickable = true;
    b2.isPickable = true;
    b3.isPickable = true;
    b4.isPickable = true;

	scene.constantlyUpdateMeshUnderPointer = true;
	
    mesh.actionManager = new BABYLON.ActionManager(scene);
    mesh.actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            {
                trigger: BABYLON.ActionManager.OnDoublePickTrigger,
            },
        function () {  
        camera.setTarget(mesh.position);
        //camera.lockedTarget = mesh.position; 
        }
        )
    );

    b1.actionManager = new BABYLON.ActionManager(scene);
    b1.actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            {
                trigger: BABYLON.ActionManager.OnDoublePickTrigger,
            },
        function () { 
            //camera.lockedTarget = b1.position;
            camera.setTarget(b1.position); 
            }
        )
    );

        b2.actionManager = new BABYLON.ActionManager(scene);
        b2.actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            {
                trigger: BABYLON.ActionManager.OnDoublePickTrigger,
            },
        function () { 
            //camera.lockedTarget = b2.position;
            camera.setTarget(b2.position); 
            }
        )
    );

        b3.actionManager = new BABYLON.ActionManager(scene);
    b3.actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            {
                trigger: BABYLON.ActionManager.OnDoublePickTrigger,
            },
        function () { 
            //camera.lockedTarget = b3.position;
            camera.setTarget(b3.position); 
            }
        )
    );

        b4.actionManager = new BABYLON.ActionManager(scene);
    b4.actionManager.registerAction(
        new BABYLON.ExecuteCodeAction(
            {
                trigger: BABYLON.ActionManager.OnDoublePickTrigger,
            },
        function () { 
            camera.lockedTarget = b4.position;
            //camera.setTarget(b4.position); 
            }
        )
    );
	return scene;
};

I did not check the code precisely but it seems to me that they are some issues in your logic
(here is your PG: Babylon.js Playground)

1 Like

You can check the console here to see that none are missed: https://www.babylonjs-playground.com/#PFKSUJ#1

(at least on my computer :slight_smile: )

1 Like

Thank you. I looked more closely at what i was doing. I’m good now.

1 Like