[SOLVED] Why can I not transfer pc.Vec3 in/to a separate function?

I cannot do this:

In a scripts update-function, I try to transfer these two vectors:
var r2b = new pc.Vec3(); var r1b = new pc.Vec3();

  • by
    this.drawAngle(1, r1b, r2b);

It is then received in:
DotVectorAngle.prototype.drawAngle = function(pos, r1bS, r2bS) {
var rXC12 = new pc.Vec3();rXC12.lerp( r2bS,r1bS, 0.11);
…}

From there I get:

'… Cannot read property ‘x’ of undefined

TypeError: Cannot read property ‘x’ of undefined …’

… as error, and it therefore seems that your additional pc.Vec3 API-coding, does support such transfers/handling? :slight_smile:

PS: No, I should not be using ‘this.’ … And no other lines should be needed as the ‘pos’, is transfered normally already.

Your code that you have shown here is fine used in the right context.

Are you calling drawAngle in a different function scope to where r2b and r1b are defined?

Yes, but I thought that r1bS (where S is for Send) would be adequate in the other scope (at other drawAngle function)

Without seeing the actual code, it’s difficult to debug. My guess is that you have defined r2b and r1b in one function scope and tried to use them in another.

Ok, fair I guess … but in such case my question is more ‘a request for more pc.-api functionality’ (the rest of the code should not be relevant - no errors otherwise, and [if I may] my experience gives ‘the rest of code’ a 0.1 percentage of chance in this case).

Not to nit-pick though … Are you sure that ‘transfer of pc.Vec3’ is possible already? and are you guys far or close to the developers of the ‘pc.’ api?

PS: One should be able to make a conversion from a vector into a list[] of the numbers, before and (back again) after, though. But is that a viable solution?

I taken the exact code you have written and it works in my test project within the context that r1b and r2b are defined in the same function context that they are used and it works as expected. Hence, I said the problem was elsewhere in your code so the rest of the code is relevant.

Eg https://playcanvas.com/project/501253/overview/console-sandbox

pc.Vec3 is a JS object so you can pass it by reference like any other JS object.

Am I’m completely misunderstanding your problem? Can you provide a sample project of what you are trying to do?

When you say transfer, do you mean take a copy of the pc.Vec3? If you do, there’s the .clone() function.

var DotVectorAngle = pc.createScript('dotVectorAngle');
DotVectorAngle.attributes.add('cameraEntity', {type: 'entity'}); 


DotVectorAngle.attributes.add('OsloPkt', {type: 'entity'}); DotVectorAngle.attributes.add('StockholmPkt', {type: 'entity'});
DotVectorAngle.attributes.add('KoebenhavnPkt', {type: 'entity'});
DotVectorAngle.attributes.add('TrondheimPkt', {type: 'entity'}); DotVectorAngle.attributes.add('TorshavnPkt', {type: 'entity'});
DotVectorAngle.attributes.add('ReykavikPkt', {type: 'entity'}); DotVectorAngle.attributes.add('HelsinkiPkt', {type: 'entity'});

DotVectorAngle.attributes.add('OsloPos', {type: 'Vec3'}); DotVectorAngle.attributes.add('StockholmPos', {type: 'Vec3'});
DotVectorAngle.attributes.add('KoebenhavnPos', {type: 'Vec3'});
DotVectorAngle.attributes.add('TrondheimPos', {type: 'Vec3'}); DotVectorAngle.attributes.add('TorshavnPos', {type: 'Vec3'});
DotVectorAngle.attributes.add('ReykavikPos', {type: 'Vec3'}); DotVectorAngle.attributes.add('HelsinkiPos', {type: 'Vec3'});

DotVectorAngle.attributes.add('aListLH', {    type: 'number',   default: 0});
DotVectorAngle.attributes.add('aListLHT', {    type: 'number',   default: 0});

DotVectorAngle.attributes.add('resultDegree1', {    type: 'number',   default: 0});
DotVectorAngle.attributes.add('resultDegree2', {    type: 'number',   default: 0});


// initialize code called once per entity
DotVectorAngle.prototype.initialize = function() { 
    var app = this.app;
    this.cameraEntity = this.app.root.findByName('Camera');
    this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.mouseDown, this);
    OsloPkt = app.root.findByName("Oslo");  StockholmPkt = app.root.findByName("Stockholm");
    OsloPos = OsloPkt.getPosition();  StockholmPos = StockholmPkt.getPosition();    
    
    KoebenhavnPkt = app.root.findByName("Koebenhavn"); KoebenhavnPos = KoebenhavnPkt.getPosition();
    
    TrondheimPkt = app.root.findByName("Trondheim");  TorshavnPkt = app.root.findByName("Torshavn");
    TrondheimPos = TrondheimPkt.getPosition();  TorshavnPos = TorshavnPkt.getPosition();   
    
    ReykavikPkt = app.root.findByName("Reykavik"); ReykavikPos = ReykavikPkt.getPosition();
    HelsinkiPkt = app.root.findByName("Helsinki"); HelsinkiPos = HelsinkiPkt.getPosition();
    
    aListLH=[]; aListLHT=[];
};

DotVectorAngle.prototype.mouseDown = function (e) {
    this.doRayCast(e); console.log("getEnt vlick");
     
};

DotVectorAngle.prototype.doRayCast = function (screenPosition) {
    
    var from = this.cameraEntity.getPosition ();//console.log(from);
    //console.log(from);
    // The vec3 to autoGenTextSquares to 
    var to = this.cameraEntity.camera.screenToWorld(screenPosition.x, screenPosition.y, this.cameraEntity.camera.farClip);

    // autoGenTextSquares between the two points
    var result = this.app.systems.rigidbody.raycastFirst(from, to);console.log(result);
    
    // If there was a hit, store the entity
    if (result) {
         var hitEntity = result.entity; console.log(hitEntity.name);
        // Set the target position of the lerp script based on the name of the clicked box
            if (hitEntity.name === 'Oslo'){        aListLH.push(OsloPos);        aListLHT.push("Oslo");           }
            if (hitEntity.name === 'Koebenhavn'){  aListLH.push(KoebenhavnPos);  aListLHT.push("Koebenhavn");    }
            if (hitEntity.name === 'Stockholm'){   aListLH.push(StockholmPos);   aListLHT.push("Stockholm");     }
            if (hitEntity.name === 'Reykavik'){    aListLH.push(ReykavikPos);    aListLHT.push("Reykavik");           }
            if (hitEntity.name === 'Torshavn'){    aListLH.push(TorshavnPos);    aListLHT.push("Torshavn");     }
            if (hitEntity.name === 'Trondheim'){   aListLH.push(TrondheimPos);   aListLHT.push("Trondheim");      }
            if (hitEntity.name === 'Helsinki'){    aListLH.push(HelsinkiPos);    aListLHT.push("Helsinki");     }
    }
};

// update code called every frame
DotVectorAngle.prototype.update = function(dt) {
   //Udfyld tekstfelter
    var txtEntAfg = this.app.root.findByName("Afgang_Indsk");       txtEntAfg.element.text = aListLHT[0];
    var txtEnt1st = this.app.root.findByName("1_stop_Indsk");       txtEnt1st.element.text = aListLHT[1];
    var txtEnt2st = this.app.root.findByName("2_stop_Indsk");       txtEnt2st.element.text = aListLHT[2];
    var txtEntDest = this.app.root.findByName("Destination_Indsk");       txtEntDest.element.text = aListLHT[3];
    
    var app = this.app;
    var colorAng1= new pc.Color(0, 0, 0); var colorAng2= new pc.Color(0, 0, 0);
    var color = new pc.Color(0, 0, 0);
    if(aListLH.length>1){
    var d = new pc.Vec3();
    d.sub2(aListLH[0], aListLH[1]);
    var distance1 = d.length();      
    app.renderLine(aListLH[0],aListLH[1], color);  
  
    var angle_S;
    if(aListLH.length>2){  angle_S =1;
    this.calculateAngle(angle_S, aListLH[0], aListLH[1],aListLH[2]); 
    if(resultDegree1>100 && resultDegree1<180){colorAng1 = new pc.Color(0, 1, 0);} if(resultDegree1>50 && resultDegree1<100.01){colorAng1 = new pc.Color(1, 1, 0);}
    if(resultDegree1>0 && resultDegree1<50.01){colorAng1 = new pc.Color(1, 0, 0);}
        //
                         
                         
    var d2 = new pc.Vec3();
    d2.sub2(aListLH[1], aListLH[2]);
    var distance2 = d2.length();
    app.renderLine(aListLH[1],aListLH[2], color); 
    
    var tmpDiff = distance2/distance1; var tmpOne = distance1/distance1;   
                         
    // Starter med 2dt ben
    var r2b = new pc.Vec3();
    r2b.lerp( aListLH[1],aListLH[2], 0.33*tmpOne);
    
    // 9. Opad
    app.renderLine(aListLH[1],r2b, colorAng1);
    
    // Dernæst første ben
    var r1b = new pc.Vec3();
    r1b.lerp( aListLH[1],aListLH[0], 0.33*tmpDiff);  
    
    // 1. Opad
    app.renderLine(aListLH[1],r1b, colorAng1);
    
    var colorBC = new pc.Color(0, 0, 1);
    // app.renderLine(r1,rD, colorBC);
                         this.drawAngle(1, r1b, r2b);
                    
    // Første fuldt tværgående:
    var rDC12 = new pc.Vec3();
    rDC12.lerp( r2b,r1b, 0.5);  
                         
    var rM = new pc.Vec3(); var length3rdKobSto = rM.sub2(aListLH[1],r2b).length();    var dM = new pc.Vec3(); var lengthBlue =  dM.sub2(aListLH[1],rDC12).length();     
    var L3KS_mult = length3rdKobSto/lengthBlue;
    
                         // X_ny; Inddelte tvaergaaende:
    var rXC12 = new pc.Vec3();rXC12.lerp( r2b,r1b, 0.11);  var rXC23 = new pc.Vec3();rXC23.lerp( rXC12,r1b, 0.125); 
    var rXC34 = new pc.Vec3();rXC34.lerp( rXC23,r1b, 0.144);  var rXC45 = new pc.Vec3();rXC45.lerp( rXC34,r1b, 0.167); 
    
    var rXC56 = new pc.Vec3();rXC56.lerp( rXC45,r1b, 0.20);  var rXC67 = new pc.Vec3();rXC67.lerp( rXC56,r1b, 0.25); 
    var rXC78 = new pc.Vec3();rXC78.lerp( rXC67,r1b, 0.33);  var rXC89 = new pc.Vec3();rXC89.lerp( rXC78,r1b, 0.50); 
             
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC12).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rRP1 = new pc.Vec3();     rRP1.lerp( aListLH[1],rXC12, L3KS_mult); app.renderLine(aListLH[1],rRP1, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC23).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rRP2 = new pc.Vec3();     rRP2.lerp( aListLH[1],rXC23, L3KS_mult); app.renderLine(aListLH[1],rRP2, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC34).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rRP3 = new pc.Vec3();     rRP3.lerp( aListLH[1],rXC34, L3KS_mult); app.renderLine(aListLH[1],rRP3, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC45).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rRP4 = new pc.Vec3();     rRP4.lerp( aListLH[1],rXC45, L3KS_mult); app.renderLine(aListLH[1],rRP4, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC56).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rRP5 = new pc.Vec3();     rRP5.lerp( aListLH[1],rXC56, L3KS_mult); app.renderLine(aListLH[1],rRP5, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC67).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rRP6 = new pc.Vec3();     rRP6.lerp( aListLH[1],rXC67, L3KS_mult); app.renderLine(aListLH[1],rRP6, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC78).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rRP7 = new pc.Vec3();     rRP7.lerp( aListLH[1],rXC78, L3KS_mult); app.renderLine(aListLH[1],rRP7, colorAng1);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[1],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[1],rXC89).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rRP8 = new pc.Vec3();     rRP8.lerp( aListLH[1],rXC89, L3KS_mult); app.renderLine(aListLH[1],rRP8, colorAng1);
    
        
    if(aListLH.length>3){ angle_S =2;
        this.calculateAngle(angle_S, aListLH[1], aListLH[2],aListLH[3]); 
        if(resultDegree2>100 && resultDegree2<180){colorAng2 = new pc.Color(0, 1, 0);} if(resultDegree2>50 && resultDegree2<100.01){colorAng2 = new pc.Color(1, 1, 0);}
        if(resultDegree2>0 && resultDegree2<50.01){colorAng2 = new pc.Color(1, 0, 0);}
             this.drawAngle(1, r1b, r2b);
                         
    var d3 = new pc.Vec3();
    d3.sub2(aListLH[2], aListLH[3]);
    var distance3 = d3.length();
    app.renderLine(aListLH[2],aListLH[3], color);                         tmpDiff = distance3/distance2; 
                         
// Starter med 2dt ben
    var r2b_2 = new pc.Vec3();
    r2b_2.lerp( aListLH[2],aListLH[3], 0.33*tmpOne);
    
    // 9. Opad
    app.renderLine(aListLH[2],r2b_2, colorAng2);
    
    // Dernæst første ben
    var r1b_2 = new pc.Vec3();
    r1b_2.lerp( aListLH[2],aListLH[1], 0.33*tmpDiff);  
    
    // 1. Opad
    app.renderLine(aListLH[2],r1b_2, colorAng2);
                         this.drawAngle(2, r1b_2, r2b_2);
                         
    // Første fuldt tværgående:
    var rDC12_2 = new pc.Vec3();
    rDC12_2.lerp( r2b_2,r1b_2, 0.5);
    //var colorDC = new pc.Color(1, 0, 1);
    // app.renderLine(r1,rDC, colorDC); // Usynlig nu   
    
    var rM_2 = new pc.Vec3(); var length3rdKobSto_2 = rM_2.sub2(aListLH[2],r2b_2).length();
    var dM_2 = new pc.Vec3(); var lengthBlue_2 =  dM_2.sub2(aListLH[2],rDC12_2).length();
     
    var L3KS_mult_2 = length3rdKobSto_2/lengthBlue_2;
    // console.log(" :: "+L3KS_mult.toFixed(2)); 
    
    var rR_2 = new pc.Vec3();                
    rR_2.lerp( aListLH[2],rDC12_2, (L3KS_mult_2+1.14)/2);   // app.renderLine(KoebenhavnPos,rDC, colorBC);
       
    var rX2C12 = new pc.Vec3();rX2C12.lerp( r2b_2,r1b_2, 0.11);    var rX2C23 = new pc.Vec3();rX2C23.lerp( rX2C12,r1b_2, 0.125); 
    var rX2C34 = new pc.Vec3();rX2C34.lerp( rX2C23,r1b_2, 0.144);  var rX2C45 = new pc.Vec3();rX2C45.lerp( rX2C34,r1b_2, 0.167); 
    
    var rX2C56 = new pc.Vec3();rX2C56.lerp( rX2C45,r1b_2, 0.20);  var rX2C67 = new pc.Vec3();rX2C67.lerp( rX2C56,r1b_2, 0.25); 
    var rX2C78 = new pc.Vec3();rX2C78.lerp( rX2C67,r1b_2, 0.33);  var rX2C89 = new pc.Vec3();rX2C89.lerp( rX2C78,r1b_2, 0.50); 
             
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C12).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rR2P1 = new pc.Vec3();     rR2P1.lerp( aListLH[2],rX2C12, L3KS_mult); app.renderLine(aListLH[2],rR2P1, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C23).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rR2P2 = new pc.Vec3();     rR2P2.lerp( aListLH[2],rX2C23, L3KS_mult); app.renderLine(aListLH[2],rR2P2, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C34).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rR2P3 = new pc.Vec3();     rR2P3.lerp( aListLH[2],rX2C34, L3KS_mult); app.renderLine(aListLH[2],rR2P3, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C45).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rR2P4 = new pc.Vec3();     rR2P4.lerp( aListLH[2],rX2C45, L3KS_mult); app.renderLine(aListLH[2],rR2P4, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C56).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rR2P5 = new pc.Vec3();     rR2P5.lerp( aListLH[2],rX2C56, L3KS_mult); app.renderLine(aListLH[2],rR2P5, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C67).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rR2P6 = new pc.Vec3();     rR2P6.lerp( aListLH[2],rX2C67, L3KS_mult); app.renderLine(aListLH[2],rR2P6, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C78).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rR2P7 = new pc.Vec3();     rR2P7.lerp( aListLH[2],rX2C78, L3KS_mult); app.renderLine(aListLH[2],rR2P7, colorAng2);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[2],r2b_2).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[2],rX2C89).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rR2P8 = new pc.Vec3();     rR2P8.lerp( aListLH[2],rX2C89, L3KS_mult); app.renderLine(aListLH[2],rR2P8, colorAng2);
       }}}
};


DotVectorAngle.prototype.drawAngle = function(pos, r1bS, r2bS) {
        // X_ny; Inddelte tvaergaaende:
    var rXC12 = new pc.Vec3();rXC12.lerp( r2bS,r1bS, 0.11);  var rXC23 = new pc.Vec3();rXC23.lerp( rXC12,r2bS, 0.125); 
    var rXC34 = new pc.Vec3();rXC34.lerp( rXC23,this.r1b, 0.144);    var rXC45 = new pc.Vec3();rXC45.lerp( rXC34,this.r1b, 0.167); 
    
    var rXC56 = new pc.Vec3();rXC56.lerp( rXC45,this.r1b, 0.20);  var rXC67 = new pc.Vec3();rXC67.lerp( rXC56,this.r1b, 0.25); 
    var rXC78 = new pc.Vec3();rXC78.lerp( rXC67,this.r1b, 0.33);  var rXC89 = new pc.Vec3();rXC89.lerp( rXC78,this.r1b, 0.50); 
    
    var colorAng;  if(pos ===1){colorAng = colorAng1;} if(pos ===2){colorAng = colorAng2;}
             
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC12).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rRP1 = new pc.Vec3();     rRP1.lerp( aListLH[pos],rXC12, L3KS_mult); app.renderLine(aListLH[pos],rRP1, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC23).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rRP2 = new pc.Vec3();     rRP2.lerp( aListLH[pos],rXC23, L3KS_mult); app.renderLine(aListLH[pos],rRP2, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC34).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rRP3 = new pc.Vec3();     rRP3.lerp( aListLH[pos],rXC34, L3KS_mult); app.renderLine(aListLH[pos],rRP3, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC45).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rRP4 = new pc.Vec3();     rRP4.lerp( aListLH[pos],rXC45, L3KS_mult); app.renderLine(aListLH[pos],rRP4, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC56).length(); L3KS_mult = length3rdKobSto/lengthBlue;
    var rRP5 = new pc.Vec3();     rRP5.lerp( aListLH[pos],rXC56, L3KS_mult); app.renderLine(aListLH[pos],rRP5, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC67).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
    var rRP6 = new pc.Vec3();     rRP6.lerp( aListLH[pos],rXC67, L3KS_mult); app.renderLine(aListLH[pos],rRP6, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC78).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
    var rRP7 = new pc.Vec3();     rRP7.lerp( aListLH[pos],rXC78, L3KS_mult); app.renderLine(aListLH[pos],rRP7, colorAng);
                         
    rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2b).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC89).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
    var rRP8 = new pc.Vec3();     rRP8.lerp( aListLH[pos],rXC89, L3KS_mult); app.renderLine(aListLH[pos],rRP8, colorAng);
};

DotVectorAngle.prototype.calculateAngle = function(ang, posEt, posTo, posTre){
    
var p2={ // Start-punkt:
    x: posEt.x,
	y: posEt.y	
};
var p1={ // Spids-punkt:
    x: posTo.x,
	y: posTo.y	
};

var p3={ // Slut-punkt:
	x: posTre.x,
	y: posTre.y
};

var p12 = Math.sqrt(Math.pow((p1.x - p2.x),2) + Math.pow((p1.y - p2.y),2));
var p13 = Math.sqrt(Math.pow((p1.x - p3.x),2) + Math.pow((p1.y - p3.y),2));
var p23 = Math.sqrt(Math.pow((p2.x - p3.x),2) + Math.pow((p2.y - p3.y),2));

//angle in radians
var resultRadian = Math.acos(((Math.pow(p12, 2)) + (Math.pow(p13, 2)) - (Math.pow(p23, 2))) / (2 * p12 * p13));

//angle in degrees
    if(ang === 1){resultDegree1 = Math.acos(((Math.pow(p12, 2)) + (Math.pow(p13, 2)) - (Math.pow(p23, 2))) / (2 * p12 * p13)) * 180 / Math.PI;}
        if(ang === 2){resultDegree2 = Math.acos(((Math.pow(p12, 2)) + (Math.pow(p13, 2)) - (Math.pow(p23, 2))) / (2 * p12 * p13)) * 180 / Math.PI;}
};

As such - Just regular OOP-handling (within the same script though)

Which line does the error point to?

Nevermind, I think I found the error:

    // X_ny; Inddelte tvaergaaende:
    var rXC12 = new pc.Vec3();
    rXC12.lerp(r2bS, r1bS, 0.11);
    var rXC23 = new pc.Vec3();
    rXC23.lerp(rXC12, r2bS, 0.125);
    var rXC34 = new pc.Vec3();
    rXC34.lerp(rXC23, this.r1b, 0.144); // This line
    var rXC45 = new pc.Vec3();
    rXC45.lerp(rXC34, this.r1b, 0.167);

this.r1b is not defined

sorry, forgot to tell - I did not go beyond the first error’ed r1bS and r2bS while debugging.
Here is the updated DotVectorAngle.prototype.drawAngle:

DotVectorAngle.prototype.drawAngle = function(pos, r1bS, r2bS) {
// X_ny; Inddelte tvaergaaende:
var rXC12 = new pc.Vec3();rXC12.lerp( this.r2bS,this.r1bS, 0.11); var rXC23 = new pc.Vec3();rXC23.lerp( rXC12,this.r2bS, 0.125);
var rXC34 = new pc.Vec3();rXC34.lerp( rXC23,this.r1bS, 0.144); var rXC45 = new pc.Vec3();rXC45.lerp( rXC34,this.r1bS, 0.167);

var rXC56 = new pc.Vec3();rXC56.lerp( rXC45,this.r1bS, 0.20);  var rXC67 = new pc.Vec3();rXC67.lerp( rXC56,this.r1bS, 0.25); 
var rXC78 = new pc.Vec3();rXC78.lerp( rXC67,this.r1bS, 0.33);  var rXC89 = new pc.Vec3();rXC89.lerp( rXC78,this.r1bS, 0.50); 

var colorAng;  if(pos ===1){colorAng = colorAng1;} if(pos ===2){colorAng = colorAng2;}
         
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC12).length(); L3KS_mult = length3rdKobSto/lengthBlue;
var rRP1 = new pc.Vec3();     rRP1.lerp( aListLH[pos],rXC12, L3KS_mult); app.renderLine(aListLH[pos],rRP1, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC23).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
var rRP2 = new pc.Vec3();     rRP2.lerp( aListLH[pos],rXC23, L3KS_mult); app.renderLine(aListLH[pos],rRP2, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC34).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
var rRP3 = new pc.Vec3();     rRP3.lerp( aListLH[pos],rXC34, L3KS_mult); app.renderLine(aListLH[pos],rRP3, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC45).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
var rRP4 = new pc.Vec3();     rRP4.lerp( aListLH[pos],rXC45, L3KS_mult); app.renderLine(aListLH[pos],rRP4, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC56).length(); L3KS_mult = length3rdKobSto/lengthBlue;
var rRP5 = new pc.Vec3();     rRP5.lerp( aListLH[pos],rXC56, L3KS_mult); app.renderLine(aListLH[pos],rRP5, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC67).length(); L3KS_mult = length3rdKobSto/lengthBlue;                         
var rRP6 = new pc.Vec3();     rRP6.lerp( aListLH[pos],rXC67, L3KS_mult); app.renderLine(aListLH[pos],rRP6, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC78).length(); L3KS_mult = length3rdKobSto/lengthBlue;                      
var rRP7 = new pc.Vec3();     rRP7.lerp( aListLH[pos],rXC78, L3KS_mult); app.renderLine(aListLH[pos],rRP7, colorAng);
                     
rM = new pc.Vec3();  length3rdKobSto = rM.sub2(aListLH[pos],r2bS).length(); dM = new pc.Vec3(); lengthBlue =  dM.sub2(aListLH[pos],rXC89).length(); L3KS_mult = length3rdKobSto/lengthBlue;                     
var rRP8 = new pc.Vec3();     rRP8.lerp( aListLH[pos],rXC89, L3KS_mult); app.renderLine(aListLH[pos],rRP8, colorAng);

};

And the error msg it produces:

[playcanvas-stable.dbg.js:1368]: Cannot read property ‘x’ of undefined

TypeError: Cannot read property ‘x’ of undefined
at Vec3.lerp (https://code.playcanvas.com/playcanvas-stable.dbg.js:1368:18)
at script.DotVectorAngle.drawAngle (https://launch.playcanvas.com/api/assets/files/Scripts/dotVectorAngle.js?id=21098074&branchId=6b12ae42-9ec3-4e36-89ff-ba07fc9999ec:244:37)
at script.DotVectorAngle.update (https://launch.playcanvas.com/api/assets/files/Scripts/dotVectorAngle.js?id=21098074&branchId=6b12ae42-9ec3-4e36-89ff-ba07fc9999ec:118:31)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:27249:21)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:27285:14)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:27667:51)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:27676:10)
at Function._helper (https://code.playcanvas.com/playcanvas-stable.dbg.js:24366:14)
at Function.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:24374:10)
at Application.update (https://code.playcanvas.com/playcanvas-stable.dbg.js:23775:24)

  • where I presume that ‘x’ is the first coordinate that it will not read from the OOP-transfered Vec3: this.r2bS
  • a: var rXC12 = new pc.Vec3();rXC12.lerp( this.r2bS,this.r1bS, 0.11);

I put this. in front as part of debugging

var rXC12 = new pc.Vec3();rXC12.lerp( this.r2bS,this.r1bS, 0.11);

It’s the same problem as before. this.r2bS is undefined I’m not sure what you are trying to do here as you haven’t assigned this.r2bS to any value or object by this point.

ok, went through it all …and it works now, thx