Can I connect a Bluetooth controller to use to Navigate around in VR?

Hey guys, I was testing a standalone occulus go on this demo I made a while back: Made with Needle

I still am testing it, but I was curious to know if we can connect a bluetooth controller to our device and use that to move around the scene, currently I own a red gear controller (https://www.amazon.in/Redgear-Pro-Wireless-Gamepad-Black/dp/B0756CLQWL) and was hoping this could extend to any xbox based or bluetooth controllers in general. Please do let me know what is possible for the same. Currently I am also in the process of trying to procure a Quest 3 by mid november.

Original Post on Discord

by user 392979063620501504

Hi, it is possible with some javascript, yes. You can write a script to move the XR rig when in VR or to move your camera object or camera parent when not.

The documentation for controllers in the browser can be found here: Using the Gamepad API - Web APIs | MDN

So basically I have to create a custom component to use use gamepads, does the current needle engine have the required dependencies exposed? Has there been any precedent cases or implementations on Needle I can refer to?

by user 392979063620501504

There are no other dependencies and yes there have been but I dont have a link right now

Okay cool, let me know where I can find them, I’d like to take a look at them if possible

by user 392979063620501504

I have no idea how to enable this or type the code required for this, might need some help in starting and setting the component up

by user 392979063620501504

You can see some usage in the Sidescroller Character

Yeah… I don’t understand much of it sorry :sweat_smile:

by user 392979063620501504

Can I use the code as it and see? is that what is it?

by user 392979063620501504

You can not use it as is :confused: you need to disect it.

i think you can use chat gpt to write it tho.

This isnt really needle related, i would advise some typescript tutorial.

What do you want to do?

Okay, let me backtrack and go through these things properly.

I have been trying to explore ways of navigation around a VR scene, cause the default one feels mid. So I came across the idea to try connecting a game pad controller, which I want to just experiment with to see different ways people engage with the same scene then

by user 392979063620501504

I’ll go through the documentation today, thanks guys

by user 392979063620501504

Hey does this code from Chatgpt look coherent to you guys?

Will be testing it later tonight cause I’m in class right now but wanted to ask before your weekend starts :sweat_smile:

`
import { Behaviour } from ‘@needle-tools/engine’;

export class GamepadMovementRotation extends Behaviour {
private speed: number = 0.05; // Adjust the movement speed
private rotationSpeed: number = 0.03; // Adjust the rotation speed
private dir: number = 1;

lateUpdate() {
const gamepad = navigator.getGamepads()[0]; // Assuming the first connected gamepad

if (gamepad) {
  // Deadzone to ignore small stick values
  const movementDeadzone = 0.1;
  const rotationDeadzone = 0.1;

  const moveX = gamepad.axes[0];
  const moveZ = -gamepad.axes[1]; // Invert for proper movement direction

  const rotateY = gamepad.axes[2];

  // Apply movement and rotation based on analog stick values
  if (Math.abs(moveX) > movementDeadzone || Math.abs(moveZ) > movementDeadzone) {
    this.move(moveX, moveZ);
  }

  if (Math.abs(rotateY) > rotationDeadzone) {
    this.rotate(rotateY);
  }
}

}

move(moveX: number, moveZ: number) {
const moveAmount = this.speed * this.context.time.deltaTime;
const pos = this.gameObject.transform.position;

pos.x += moveX * moveAmount;
pos.z += moveZ * moveAmount;

}

rotate(rotateY: number) {
const rotateAmount = this.rotationSpeed * this.context.time.deltaTime;
const rot = this.gameObject.transform.rotation;

rot.y += rotateY * rotateAmount;

}
}
`

by user 392979063620501504

by user 392979063620501504

Could work

hey, hope you guys are having a good weekend, just wanted to ping that my component are acting weird on needle, the new components I make keep disappearing from the menu even after I save them or when they do appear and I add them, all the previously applied components disappear instead and they don’t show up. Been happening since yesterday

by user 392979063620501504

Okay update cause this has stumped me: Any new component I make and add removes ALL previously added components on all objects from view, web XR still works despite the component not being seen on where I added it, and essentially also stops me from adding any existing or new components to scene there after

by user 392979063620501504

Sent in a bug report, is it possible to download an older version of needle? Just to check it’s not an issue on my end

by user 392979063620501504

Thanks for the bugreport. We will look into that.

Other versions are still online, which version are you currently using and did use before? Ill have to lookup the url later