ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Custom Controller Help (Advanced)
person icon
ArchAngel
Guest
Quote
2025-03-02 16:50:36

any idea how to get this custom controller animator to work with the engine in webgl target, currently when i run it theres no errors but the camera still wont move or rotate.

in onXRFrame() i call camera.addAnimator(new CL3D.AnimatorXRCameraFPS(session, camera, engine));
and handleController(inputSource);

function handleController(inputSource) {
let camera = engine.getScene().getActiveCamera();
let animator = camera.Animators[3];
const gamepad = inputSource.gamepad;
if (!gamepad) return;

console.log("Gamepad Debug:", gamepad);
console.log("Axes Data:", gamepad.axes);

// Assign the gamepad axes to the relevant controller (e.g., left controller)
const [xAxis, yAxis] = gamepad.axes;

// Check if movement on the joystick is significant
if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) {
console.log(`Joystick Moved - X: ${xAxis.toFixed(2)}, Y: ${yAxis.toFixed(2)}`);

// Update the movement vector for the XR controller
if (inputSource.handedness === 'left') {
// Update left controller's gamepad input for animator to process
animator.xrControllers[0].gamepad.axes = [xAxis, yAxis];
} else if (inputSource.handedness === 'right') {
// Update right controller's gamepad input for animator to process
animator.xrControllers[1].gamepad.axes = [xAxis, yAxis];
}
}

// Handle button presses (optional)
gamepad.buttons.forEach((button, index) => {
if (button.pressed) {
console.log(`Button ${index} pressed`);
}
});
}


this is my Animator so far::


[code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) {
this.Type = 'xrcamerafps';

// Store the XR session and the reference space for local movement
this.xrSession = session;
this.xrReferenceSpace = 'local';

// Initialize XR controllers
this.xrControllers = [null, null]; // Two controllers (left and right)

// Movement and rotation speeds
this.moveSpeed = 0.06;
this.rotateSpeed = 2.0;

// Vertical rotation limit
this.verticalLimit = 88.0;

// Camera position and target setup
this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0);
this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1);

// Relative rotations to keep track of camera pitch and yaw
this.relativeRotationX = 0;
this.relativeRotationY = 0;

// Zooming capabilities
this.zoomSpeed = 0.05;
this.targetZoomValue = 90;
this.minZoom = 20;
this.maxZoom = 100;

// Handling key states (for teleports or additional inputs)
this.jumpKeyDown = false;

this.lastAnimTime = CL3D.CLTimer.getTime();
this.Camera = engine.getScene().getActiveCamera();
this.CursorControl = engine;


if (camera)
camera.setTarget(this.originalTarget);


this.lastMoveVector = new CL3D.Vect3d(0, 0, 0);
this.lastMoveTime = 0;
this.moveSmoothing = 0; // You can use smoothing here if needed

};

// Extending the Animator prototype
CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator();

// Get the type of the animator
CL3D.AnimatorXRCameraFPS.prototype.getType = function() {
return 'xrcamerafps';
};

// Animate the node (i.e., handle the camera movement and update each frame)
CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) {
if (!this.Camera) return false;

const now = CL3D.CLTimer.getTime();
const timeDiff = now - this.lastAnimTime;
if (timeDiff === 0) return false;

if (timeDiff > 250) timeDiff = 250;
this.lastAnimTime = now;

// Handle movement based on XR controllers (left and right)
const moveVect = new CL3D.Vect3d(0, 0, 0);

// Using controller axes (joystick) data for movement
i

person icon
ArchAngel
Guest
Quote
2025-03-02 16:52:18

[code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) {
this.Type = 'xrcamerafps';

// Store the XR session and the reference space for local movement
this.xrSession = session;
this.xrReferenceSpace = 'local';

// Initialize XR controllers
this.xrControllers = [null, null]; // Two controllers (left and right)

// Movement and rotation speeds
this.moveSpeed = 0.06;
this.rotateSpeed = 2.0;

// Vertical rotation limit
this.verticalLimit = 88.0;

// Camera position and target setup
this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0);
this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1);

// Relative rotations to keep track of camera pitch and yaw
this.relativeRotationX = 0;
this.relativeRotationY = 0;

// Zooming capabilities
this.zoomSpeed = 0.05;
this.targetZoomValue = 90;
this.minZoom = 20;
this.maxZoom = 100;

// Handling key states (for teleports or additional inputs)
this.jumpKeyDown = false;

this.lastAnimTime = CL3D.CLTimer.getTime();
this.Camera = engine.getScene().getActiveCamera();
this.CursorControl = engine;


if (camera)
camera.setTarget(this.originalTarget);


this.lastMoveVector = new CL3D.Vect3d(0, 0, 0);
this.lastMoveTime = 0;
this.moveSmoothing = 0; // You can use smoothing here if needed

};

// Extending the Animator prototype
CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator();

// Get the type of the animator
CL3D.AnimatorXRCameraFPS.prototype.getType = function() {
return 'xrcamerafps';
};

// Animate the node (i.e., handle the camera movement and update each frame)
CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) {
if (!this.Camera) return false;

const now = CL3D.CLTimer.getTime();
const timeDiff = now - this.lastAnimTime;
if (timeDiff === 0) return false;

if (timeDiff > 250) timeDiff = 250;
this.lastAnimTime = now;

// Handle movement based on XR controllers (left and right)
const moveVect = new CL3D.Vect3d(0, 0, 0);

// Using controller axes (joystick) data for movement
if (this.xrControllers[0]) {
const gamepad = this.xrControllers[0].gamepad;
if (gamepad) {
const [xAxis, yAxis] = gamepad.axes;
if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) {
moveVect.X += xAxis * this.moveSpeed * timeDiff;
moveVect.Z += yAxis * this.moveSpeed * timeDiff;
}
}
}

if (this.xrControllers[1]) {
const gamepad = this.xrControllers[1].gamepad;
if (gamepad) {
const [xAxis, yAxis] = gamepad.axes;
if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) {
moveVect.X += xAxis * this.moveSpeed * timeDiff;
moveVect.Z += yAxis * this.moveSpeed * timeDiff;
}
}
}

// Apply the movement to the camera
this.Camera.Pos.addToThis(moveVect);
this.Camera.setTarget(this.Camera.Pos.add(moveVect));

// Rotation based on controller rotation (can be modified based on your needs)
if (this.xrControllers[0] && this.xrControllers[1]) {
const rotation = new CL3D.Vect3d(
this.xrControllers[0].rotation.x + this.xrControllers[1].rotation.x,
this.xrControllers[0].rotation.y + this.xrControllers[1].rotation.y,
0
);

this.relativeRotationX += rotation.x * this.rotateSpeed * timeDiff;
this.relativeRotationY += rotation.y * this.rotateSpeed * timeDiff;

if (this.relativeRotationX > this.verticalLimit) this.relativeRotationX = this.verticalLimit;
if (this.relativeRotationX < -this.verticalLimit) this.relativeRotationX = -this.verticalLimit;
}

// Zoom handling (adjust as needed)
const fo

person icon
ArchAngel
Guest
Quote
2025-03-02 16:54:42

[code]CL3D.AnimatorXRCameraFPS = function(session, camera, engine) {
this.Type = 'xrcamerafps';

// Store the XR session and the reference space for local movement
this.xrSession = session;
this.xrReferenceSpace = 'local';

// Initialize XR controllers
this.xrControllers = [null, null]; // Two controllers (left and right)

// Movement and rotation speeds
this.moveSpeed = 0.06;
this.rotateSpeed = 2.0;

// Vertical rotation limit
this.verticalLimit = 88.0;

// Camera position and target setup
this.originalPosition = camera ? camera.Pos.clone() : new CL3D.Vect3d(0, 0, 0);
this.originalTarget = camera ? camera.getTarget().clone() : new CL3D.Vect3d(0, 0, 1);

// Relative rotations to keep track of camera pitch and yaw
this.relativeRotationX = 0;
this.relativeRotationY = 0;

// Zooming capabilities
this.zoomSpeed = 0.05;
this.targetZoomValue = 90;
this.minZoom = 20;
this.maxZoom = 100;

// Handling key states (for teleports or additional inputs)
this.jumpKeyDown = false;

this.lastAnimTime = CL3D.CLTimer.getTime();
this.Camera = engine.getScene().getActiveCamera();
this.CursorControl = engine;


if (camera)
camera.setTarget(this.originalTarget);


this.lastMoveVector = new CL3D.Vect3d(0, 0, 0);
this.lastMoveTime = 0;
this.moveSmoothing = 0; // You can use smoothing here if needed

};
CL3D.AnimatorXRCameraFPS.prototype = new CL3D.Animator();
CL3D.AnimatorXRCameraFPS.prototype.getType = function() {
return 'xrcamerafps';
};
CL3D.AnimatorXRCameraFPS.prototype.animateNode = function(n, timeMs) {
if (!this.Camera) return false;

const now = CL3D.CLTimer.getTime();
const timeDiff = now - this.lastAnimTime;
if (timeDiff === 0) return false;

if (timeDiff > 250) timeDiff = 250;
this.lastAnimTime = now;
const moveVect = new CL3D.Vect3d(0, 0, 0);
if (this.xrControllers[0]) {
const gamepad = this.xrControllers[0].gamepad;
if (gamepad) {
const [xAxis, yAxis] = gamepad.axes;
if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) {
moveVect.X += xAxis * this.moveSpeed * timeDiff;
moveVect.Z += yAxis * this.moveSpeed * timeDiff;
}
}
}
if (this.xrControllers[1]) {
const gamepad = this.xrControllers[1].gamepad;
if (gamepad) {
const [xAxis, yAxis] = gamepad.axes;
if (Math.abs(xAxis) > 0.05 || Math.abs(yAxis) > 0.05) {
moveVect.X += xAxis * this.moveSpeed * timeDiff;
moveVect.Z += yAxis * this.moveSpeed * timeDiff;
}
}
}
this.Camera.Pos.addToThis(moveVect);
this.Camera.setTarget(this.Camera.Pos.add(moveVect));
if (this.xrControllers[0] && this.xrControllers[1]) {
const rotation = new CL3D.Vect3d(
this.xrControllers[0].rotation.x + this.xrControllers[1].rotation.x,
this.xrControllers[0].rotation.y + this.xrControllers[1].rotation.y,
0
);

this.relativeRotationX += rotation.x * this.rotateSpeed * timeDiff;
this.relativeRotationY += rotation.y * this.rotateSpeed * timeDiff;

if (this.relativeRotationX > this.verticalLimit) this.relativeRotationX = this.verticalLimit;
if (this.relativeRotationX < -this.verticalLimit) this.relativeRotationX = -this.verticalLimit;
}
const fov = this.Camera.getFov();
this.targetZoomValue += this.getAdditionalZoomDiff() * timeDiff;
if (this.targetZoomValue < this.minZoom) this.targetZoomValue = this.minZoom;
if (this.targetZoomValue > this.maxZoom) this.targetZoomValue = this.maxZoom;
this.Camera.setFov(CL3D.degToRad(this.targetZoomValue));
const target = new CL3D.Vect3d(0, 0, 1);
const mat = new CL3D.Matrix4();
mat.setRotationDegrees(new CL3D.Vect3d(thi

person icon
ArchAngel
Guest
Quote
2025-03-02 16:55:32

sorry the animator wont upload correctly


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |