Camera not flying

I want to fly the camera when pick the part of car, but it not flies

if(isBodyPaint){

                this.changeColor(mat);
                
                console.log(this.bodySpot.getPosition());
                
                this.flyTo();

...
flyTo(){
        
        this.entity.setPosition(this.bodySpot.getPosition());
        console.log('fly to');

    }

What do you mean by this quote?

I mean I want to fly with the camera to given hotspot but it not flies

Oh, please link to editor? I can see what you want.

https://playcanvas.com/editor/scene/1096043

Hello @grzesiekmq

I just want you to mind that this might be the error. On line 27 in jscolour.js you missed a semicolon

this is 3rd party code (jscolor.js)

Can you tell me which script to look at because I really can’t see the real one :thinking:

PickerFramebuffer.js

1 Like

/*jshint esversion: 6 */

class PickerFramebuffer extends pc.ScriptType{

initialize(){
    this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);
    this.picker = new pc.Picker(this.app, 1024, 1024);

    this.container = this.entity.parent.script.main.div;

}
onSelect(e) {
    const picker = this.picker;
    picker.prepare(this.entity.camera, this.app.scene);

    const canvas = document.querySelector('#application-canvas');
    const canvasWidth = canvas.clientWidth;
    const canvasHeight = canvas.clientHeight;

    const selection = picker.getSelection({
        x: Math.floor(event.x * (picker.width / canvasWidth)), 
        y: picker.height - Math.floor(event.y * (picker.height / canvasHeight))
    });

    const selectedItem = selection[0];
    
    if(selection.length > 0 && selectedItem !== undefined){


        const nodeName = selectedItem.node.name;

        const bodyPaint = 'Cube_2_3';

        const wheel = 'wheel';
        
        const isWheel = nodeName.includes(wheel);


        
        console.log(selection);
        
        console.log(selectedItem.node.name);
            

        const isBodyPaint = nodeName === bodyPaint;

        const mat = selectedItem.material;
        

        
        
        this.container.style.display = 'inline';

        if(isBodyPaint){

            this.flyTo();
          
            this.changeColor(mat);
            
            
            
            
            console.log(this.bodySpot.getPosition());
            
            

        }
       else if(isWheel){
            
            const wheelSpotPos = this.wheelsSpot.getPosition();
            
            this.flyTo(wheelSpotPos);
           
            this.changeColor(mat);

        }
    }
}
changeColor(mat){
    this.container.addEventListener('change', () => {
        const color = new pc.Color().fromString(this.container.value);
        mat.diffuse = color;
        mat.update();
        
        console.log('updated mat', mat);

    });
}
flyTo(){
    
    this.entity.setPosition(this.bodySpot.getPosition());
    console.log('fly to');

}

}

pc.registerScript(PickerFramebuffer, ‘PickerFramebuffer’);

PickerFramebuffer.attributes.add(‘bodySpot’, {type:‘entity’});
PickerFramebuffer.attributes.add(‘wheelsSpot’, {type:‘entity’});

Im not sure if this is the problem but is it supposed to be ‘‘inline’’
this.container.style.display = ‘inline’;
Also Im pretty sure this is a problem too.
this.container.addEventListener(‘change’, () => {

Because you don’t have a ‘Event Listener’ on one of your components.

I think here it is the event listener
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);

For that, I can see straight off the bat that the event listener is not applyed (I might not be thinking correctly because I have maths rn)

Im pretty sure its this

this.app.mouse.on(pc.EVENT_LISTENER, this.onSelect, this); (I dont know honestly Im tired)

I dont see pc.EVENT_LISTENER in API

:thinking: Im not sure, I had done a script like that before and it worked :confused:

I mean it console logs ‘fly to’ but not changing position, mean the camera

Oh, then im not sure :confused: Is it possible if you can wait 20 minutes? My school ends then I can focus on it?

1 Like

sure!

1 Like

Then I’ll fork it and see the problem.