cosmos
September 21, 2022, 8:42am
1
i m trying to move camera using virtual joysticks but the collision doesn’t work, how to fix this.
const leftJoystick = new VirtualJoystick(true);
const rightJoystick = new VirtualJoystick(false);
VirtualJoystick.Canvas!.style.zIndex = '4';
const movespeed = 5;
scene!.onBeforeRenderObservable.add(() => {
if (leftJoystick.pressed) {
const moveX =
leftJoystick.deltaPosition.x *
(scene!.getEngine()!.getDeltaTime() / 1000) *
movespeed;
const moveZ =
leftJoystick.deltaPosition.y *
(scene!.getEngine()!.getDeltaTime() / 1000) *
movespeed;
scene!.activeCamera!.position.x += moveX;
scene!.activeCamera!.position.z += moveZ;
}
RaananW
September 21, 2022, 10:56am
2
Collision will work only if you use moveWithCollision
, otherwise the camera will only move from one point to the other:
cosmos
September 21, 2022, 11:08am
3
My camera already has ellipsoid added and collision set to true.
Do I need to add a parent mesh and camera as child of it to move using this method as moveWithCollision is only available on mesh types?
RaananW
September 21, 2022, 11:12am
4
Oh! Sorry I automatically moved to mesh collision.
Are you using the virtual joystick as a camera input? Instead of using the virtual keyboard directly, use the FreeCameraVirtualJoystickInput
and add it to your camera inputs array. This way the virtual keyboard will change the camera’s position for you and will include collisions as well.
1 Like
cosmos
September 21, 2022, 1:03pm
5
Thanks! @RaananW , FreeCameraVirtualJoystickInput
worked like charm.
Is there a way reverse the joystick functionality i.e., move with right and look with left.
RaananW
September 21, 2022, 1:15pm
6
pinging @PolygonalSun for this one
As far as I know, there is no way to reverse the joystick behaviors with the FreeCameraVirtualJoystickInput
. You might have to create a custom camera input for that one.
cosmos
September 22, 2022, 7:12am
8
Thanks @PolygonalSun , where can i find the default code for FreeCameraVirtualJoystickInput, so that i can take reference from it
RaananW
September 22, 2022, 9:41am
9
1 Like