New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

three-joystick

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-joystick

A joystick for three.js

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by12.5%
Maintainers
1
Weekly downloads
 
Created
Source

three-joystick

An open source joystick that can be used to control a target in a three.js scene.

Installation

npm i three-joystick

JoystickControls Usage

This class will add a joystick that invokes a callback function with the delta x and delta y from the movement of the user.
See demo here
See example code here

  1. Import the JoystickControls class
    import { JoystickControls } from 'three-joystick';
    
  2. Pass through your camera and scene
    const joystickControls = new JoystickControls(
      camera,
      scene,
    );
    
  3. Invoke update in your animate loop
    function animate() {
      requestAnimationFrame(animate);
    
      /**
       * Updates a callback function with the delta x and delta y of the users
       * movement
       */
      joystickControls.update((movement) => {
        if (movement) {
          /**
           * The values reported back might be too large for your scene.
           * In that case you will need to control the sensitivity.
           */
          const sensitivity = 0.0001;
    
          /**
           * Do something with the values, for example changing the position
           * of the object
           */
          this.target.position.x += movement.moveX * sensitivity;
          this.target.position.y += movement.moveY * sensitivity;
        }
      });
    
      renderer.render(scene, camera);
    }
    
    animate();
    

RotationJoystickControls Usage

This class will add a joystick that can rotate a target object.
See demo here
See example code here

  1. Import the RotationJoystickControls class
    import { RotationJoystickControls } from 'three-joystick';
    
  2. Pass through your camera, scene and the target mesh you want to control
    const joystickControls = new RotationJoystickControls(
      camera,
      scene,
      target,
    );
    
  3. Invoke update in your animate loop
    function animate() {
      requestAnimationFrame(animate);
    
      /**
       * Updates the rotation of the target mesh
       */
      rotationJoystick.update();
    
      renderer.render(scene, camera);
    }
    
    animate();
    

Keywords

FAQs

Package last updated on 29 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc