Hello, I need some help on the following code:
CameraMovement.prototype.onMouseWheel = function (event) {
this.entity.translate (0,0, event.wheel * 10);
};
The camera is attached to a camera axis, under an entity that contains a walking avatar. Can I set the camera position or translate it to adjust the distance between the avatar and camera?
Thank you so much!
Hi @ntleung and welcome,
You can check mouse wheel zoom works in the orbit camera example. Here is the example:
https://playcanvas.github.io/#/camera/orbit
And here is the script code:
////////////////////////////////////////////////////////////////////////////////
// Orbit Camera Script //
////////////////////////////////////////////////////////////////////////////////
var OrbitCamera = pc.createScript('orbitCamera');
OrbitCamera.attributes.add('distanceMax', { type: 'number', default: 0, title: 'Distance Max', description: 'Setting this at 0 will give an infinite distance limit' });
OrbitCamera.attributes.add('distanceMin', { type: 'number', default: 0, title: 'Distance Min' });
OrbitCamera.attributes.add('pitchAngleMax', { type: 'number', default: 90, title: 'Pitch Angle Max (degrees)' });
OrbitCamera.attributes.add('pitchAngleMin', { type: 'number', default: -90, title: 'Pitch Angle Min (degrees)' });
OrbitCamera.attributes.add('inertiaFactor', {
type: 'number',
default: 0,
title: 'Inertia Factor',
description: 'Higher value means that the camera will continue moving after the user has stopped dragging. 0 is fully responsive.'
});
OrbitCamera.attributes.add('focusEntity', {
type: 'entity',
title: 'Focus Entity',
This file has been truncated. show original
1 Like
In your case, changing translate
to translateLocal
may be enough for you so that you move the camera along the local Z axis rather than the world
1 Like
Thanks a lot for the help! Will try the above solutions