I have a model that has a variety of regions to zoom in on, is it possible to create states of a camera each with its own xyz setting that can be transformed to on mousclick events on UI elements?
State1 = camera position X Y Z, State2 = camera other position X Y Z, etc… then Button One activates Camera State 1, Button Two activates Camera State 2 and so on?
Perhaps similar to that BMW brand experience example we’ve seen. BMW i8 - PLAYCANVAS
On each mouse click you can have an attribute that sets the camera position accordingly, even reference a scene entity as an attribute and grab the position from it. That way you can visually, in editor, place your regions.
Thanks or the info, are there any tutorials covering the movement of cameras to positions on events? Are there any scripts available that show this process being done?
So to move a camera, you are moving the entity that has the camera component attached. Here is an example on how to animate the camera along a path, observe how position/rotation are animated using the Curve class:
To get and set the position of an Entity, please use getPosition() and setPosition() (details of usage in the link above). eg
var CameraPoint1 = pc.createScript('cameraPoint1');
CameraPoint1.attributes.add('ActiveCamera', {type: 'entity'});
CameraPoint1.attributes.add('CameraTarget', {type: 'entity'});
// initialize code called once per entity
CameraPoint1.prototype.initialize = function() {
this.entity.button.on('click', function(event) {
this.ActiveCamera.setPosition(this.CameraTarget.getPosition());
}, this);
};
In terms of getting started with learning PlayCanvas, our crash course is probably the best starting point if you already know programming or used other games engines: Crash Course - Make a Game | Learn PlayCanvas
Thanks for that info. ActiveCamera is just a variable name I made, I changed the variable names in case of a namespace issue, but this still does not move the camera:
var CameraPoint1 = pc.createScript('cameraPoint1');
CameraPoint1.attributes.add('moveCamera', {type: 'entity'});
CameraPoint1.attributes.add('moveTarget', {type: 'entity'});
// initialize code called once per entity
CameraPoint1.prototype.initialize = function() {
this.entity.button.on('click', function(event) {
this.moveCamera.setPosition(this.moveTarget.getPosition());
}, this);
};
I also changed the names of the entities to be more unique for clarity:
The JS coding I am accustomed to is very different from what I’m seeing on this platform.
The reason why it doesn’t move to that position, is because the orbitCamera script on the camera entity is controlling the entity position each frame in the update.
There’s an API on the orbitCamera script that allows you to move it to a specific position (like a teleport).