Jump to content

Attach virtualjoystick to arcrotativecamera


drunkly
 Share

Recommended Posts

Hi Everyone.

I'm developing a game and I'm having problems with the controlss.

I would like to do the same behaviour as VirtualJoystickCamera but including a mesh player. To do that, I add a virtual left joystick and check if the button is pressed to move the player (the camera follow always the player).

However when I add the right virtual joystick I'm not able to rotate the camera or I'm not able to bind this joystick to the current camera.

Anyone had this problem and could solve it? Do you know where to found the source code for the VJC?.

Thanks in advance.

Link to comment
Share on other sites

//create joysticks
leftJ = new BABYLON.VirtualJoystick(true);
leftJ.setJoystickColor('red');
rightJ = new BABYLON.VirtualJoystick(false);
rightJ.setJoystickColor('lime');

//on the loop
 engine.runRenderLoop(function() {
            scene.render();
            if (scene.isReady() && meshPlayer) {
                if (leftJ.pressed) {
                    if (leftJ.deltaPosition.y > 0) {
                        keys.up= 1;
                        keys.down= 0;
                    } else if (leftJ.deltaPosition.y < 0) {
                        keys.up= 1;
                        keys.down= 0;
                    } else {
                        keys.up= 0;
                        keys.down= 0;
                    }
                    if (leftJ.deltaPosition.x > 0) {
                        keys.left = 1;
                    } else if (leftJ.deltaPosition.x < 0) {
                        keys.right = 1;
                    } else {
                        keys.left = 0;
                        keys.right = 0;
                    }
                } else {
                    keys.up= 0;
                    keys.down= 0;
                    keys.left = 0;
                    keys.right = 0;
                    PlayAnnimation = false;
                    scene.stopAnimation(skeletonsPlayer[0]);



                }
                //ROTATE CAMERA. -10000 is the rotation speed (negative to reverse direction)
                if (rightJ.pressed) {
                    cameraArcRotative[0].alpha += rightJ._deltaJoystickVector.x/-10000;
                    cameraArcRotative[0].beta += rightJ._deltaJoystickVector.y/-10000;
                }
            }
        });

If someone has also problems with this issue the trick is update the alpha and beta parameters for the arcrotatecamera

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...