I am working on a Harry Potter game, and I can’t get the
// initialize code called once per entity
Spells.prototype.initialize = function() {
var wandposition(this.wand.getlocalposition());
this.wand = this.entity.findByName(this.wandname);
this.camra = this.entity.findByName(this.camra);
};
The script is called Spells, the var is for finding the position. Later in code, I have this…
Spells.prototype.spellfire = function(dt){
this.entity.clone(
this.clone.setposition(wandposition)
);
};
When I try this it says : Uncaught TypeError: Cannot read properties of undefined (reading ‘getlocalposition’)
TypeError: Cannot read properties of undefined (reading ‘getlocalposition’)
at https://launch.playcanvas.com/api/assets/files/Scripts/Spells.js?id=124993240&branchId=64347a85-ef63-4835-b74e-cf0c7f62d98f:26:30
Here is the full script.
var Spells = pc.createScript('spells');
Spells.attributes.add('spell', {
type: 'string',
array: false
});
Spells.attributes.add('spell_type', {
description: 'DMG1, ESS2, CON3, FOR4, UILT5',
type: 'number',
default: 1
});
Spells.attributes.add('spell_type_spacific', {
description: 'fire1, ',
type: 'number',
default: 1
});
Spells.attributes.add('wandname', {
description: 'wand name',
type: 'string',
array: false
});
Spells.attributes.add('camra', {
description: 'camra',
type: 'string',
array: false
});
var wandposition = this.wand.getlocalposition;
// initialize code called once per entity
Spells.prototype.initialize = function() {
var wandposition(this.wand.getlocalposition());
this.wand = this.entity.findByName(this.wandname);
this.camra = this.entity.findByName(this.camra);
};
Spells.prototype.update = function(){
if(this.app.keyboard.isPressed(pc.KEY_Z)){
this.spellfire();
}
};
Spells.prototype.spellfire = function(dt){
this.entity.clone(
this.clone.setposition(wandposition)
);
};
// swap method called for script hot-reloading
// inherit your script state here
// Spells.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
I will appreciate any advice you have!