ok i’m doing the multiplayer trying to play the animation of the other player but it doesn’t work i goth this
Trying to play anim stand1
AnimationComponent
activate
:
true
animEvaluator
:
null
animationsIndex
:
{29524122: 'stand1.json', 29750526: 'bow.json', 29750531: 'sit.json', 29750535: 'repair.json', 29750637: 'picklock.json', 29750643: 'archer-pray.json', 29750648: 'working.json', 29750775: 'cast1HA3.json', 29750779: 'cast1HS1.json', 29819055: 'guard.json', 29887763: 'walk-staff.json', 29888691: 'orc club attack.json', 29888693: 'orc club die.json', 29890403: 'run anim.json', 30024061: 'raiseundead.json', 30024176: 'trowing.json', 32652247: 'walk.json'}
blend
:
1
blendSpeed
:
5
blending
:
false
currAnim
:
"stand1.json"
entity
:
Entity {_callbacks: Map(4), _callbackActive: Map(0), tags: Tags, localPosition: Vec3, localRotation: Quat, …}
fromSkel
:
Skeleton {looping: true, _animation: Animation, _time: 0, _interpolatedKeys: Array(35), _interpolatedKeyDict: {…}, …}
model
:
Model {graph: GraphNode, meshInstances: Array(2), skinInstances: Array(1), morphInstances: Array(0), cameras: Array(0), …}
playing
:
true
prevAnim
:
"stand1.json"
skeleton
:
Skeleton {looping: true, _animation: Animation, _time: 0, _interpolatedKeys: Array(35), _interpolatedKeyDict: {…}, …}
speed
:
1
system
:
AnimationComponentSystem {_callbacks: Map(1), _callbackActive: Map(0), app: AppBase, store: {…}, schema: Array(1), …}
toSkel
:
Skeleton {looping: true, _animation: Animation, _time: 0, _interpolatedKeys: Array(35), _interpolatedKeyDict: {…}, …}
_animations
:
{stand1.json: Animation, orc club die.json: Animation, orc club attack.json: Animation, run anim.json: Animation, bow.json: Animation, …}
_assets
:
(17) [29524122, 29888693, 29888691, 29890403, 29750526, 29887763, 29750637, 29750643, 29750648, 29750775, 29750779, 30024061, 29750535, 29750531, 30024176, 29819055, 32652247]
_callbackActive
:
Map(0) {size: 0}
_callbacks
:
Map(2) {'set' => Array(1), 'set_enabled' => Array(1)}
_loop
:
true
animations
:
(…)
assets
:
(…)
currentTime
:
(…)
data
:
(…)
duration
:
(…)
enabled
:
(…)
loop
:
(…)
[[Prototype]]
:
Component
and this is the code
var PlayerRemote = pc.createScript('playerRemote');
PlayerRemote.prototype.initialize = function () {
// flag esplicito
this.isRemote = true;
// character
this.id = 0;
this.user = "?";
this.name = "Unknown";
this.race = "Human";
this.sex = "M";
this.hp = 100;
this.maxHp = 100;
this.wmap = 0;
this.wxmap = null;
this.localMap = 0;
this.depth = 0;
this.modelName = "HumanM";
this.model=null;
this.texTure = "HumanM";
this.clasTexture = "HumanM";
this.modelKey = null;
this.blendTime = 0.2;
this.lastServerPos = new pc.Vec3();
this.targetServerPos = new pc.Vec3();
this.lastServerRot = new pc.Quat();
this.targetServerRot = new pc.Quat();
this.interpTimer = 0;
this.interpDuration = 0.15; // 50ms
this.equipSlots = {
weapon: null,
shield: null,
chest: null
};
// stato ricevuto dal server
this.netState = {
position: new pc.Vec3(),
rotation: new pc.Vec3(),
anim: 'stand1',
speed: 1,
equip: {}
};
this.models = {
HumanM: this.entity.findByName('HumanM'),
HumanF: this.entity.findByName('HumanF'),
ElfM: this.entity.findByName('ElfM'),
ElfF: this.entity.findByName('ElfF'),
DwarfM: this.entity.findByName('DwarfM'),
DwarfF: this.entity.findByName('DwarfF'),
HalforcM: this.entity.findByName('HalforcM'),
HalforcF: this.entity.findByName('HalforcF')
};
// stato equip visivo (NON logico)
this.visualEquip = {
WEAPON: null,
WEAPON2: null,
SHIELD: null,
SHIELD2: null,
HELM:null
};
this.setModel(this.race, this.sex);
};
PlayerRemote.prototype.applyNetState = function (state) {
// posizione
if (state.playerPos) {
this.lastServerPos.copy(this.targetServerPos);
this.targetServerPos.set(state.playerPos.x, state.playerPos.y, state.playerPos.z);
this.interpTimer = 0;
}
if (state.rotation) {
this.lastServerRot.copy(this.targetServerRot);
this.targetServerRot.set(state.rotation.x, state.rotation.y, state.rotation.z, state.rotation.w);
this.interpTimer = 0;
}
// animazione
if (state.anim && state.anim !== this.currentAnim) {
this.playAnim(state.anim, state.speed);
}
// equipaggiamento (più avanti)
if (state.equip) {
this.applyEquip(state.equip);
}
};
PlayerRemote.prototype.update = function (dt) {
if (!this.targetServerPos) return;
this.interpTimer += dt;
var t = Math.min(this.interpTimer / this.interpDuration, 1);
// posizione
var lerpPos = new pc.Vec3();
lerpPos.lerp(this.lastServerPos, this.targetServerPos, t);
this.entity.setPosition(lerpPos);
// rotazione
var rot = new pc.Quat();
rot.slerp(this.lastServerRot, this.targetServerRot, t);
this.entity.setRotation(rot);
};
PlayerRemote.prototype.playAnim = function (name, speed) {
if (!this.model || !this.model.animation) return;
if (this.currentAnim === name) return;
console.log(this.currentAnim, name);
this.model.enabled = true; // safety
this.currentAnim = name;
this.model.animation.speed = speed || 1;
this.model.animation.loop = true;
console.log("Trying to play anim", name, this.model?.animation);
this.model.animation.play(name+".json", this.blendTime);
};
PlayerRemote.prototype.setModel = function (race, sex) {
this.modelName = race + sex;
var modelEntity = this.models[this.modelName];
console.log("Entity in setmodel:"+modelEntity);
if (!modelEntity) {
console.warn("Model not found:", this.modelName);
return;
}
modelEntity.enabled = true;
// 🔥 toggle per far partire le animazioni e riallineare scheletro
modelEntity.enabled = false;
modelEntity.enabled = true;
this.model = modelEntity; // ✅ ENTITY
if (this.sex==="M") {
this.model.model.model.meshInstances[0].material = this.app.assets.find(this.texTure,'material').resources[0];
} else {
this.model.model.model.meshInstances[1].material = this.app.assets.find(this.texTure,'material').resources[0];
}
};
PlayerRemote.prototype.applyEquip = function (equip) {
var modelEntity = this.model;
if (!modelEntity) return;
// ---- HELPERS ----
function disableIfNotEqual(slotName, currentObjName, newObjName) {
if (currentObjName && currentObjName !== newObjName) {
var ent = modelEntity.findByName(currentObjName);
if (ent) ent.enabled = false;
}
}
function enableIfNew(slotName, currentObjName, newObjName, attachFn) {
if (!newObjName) return;
// se è già equipaggiato lo stesso, non fare nulla
if (currentObjName === newObjName) return;
// disabilita vecchio se diverso
disableIfNotEqual(slotName, currentObjName, newObjName);
// attacca il nuovo
attachFn(newObjName);
// salva nel visualEquip
this.visualEquip[slotName] = newObjName;
}
// ---- ARMOUR (material change) ----
if (equip.ARMOUR && equip.ARMOUR.obj) {
var matName = equip.ARMOUR.obj; // nome del material in assets
var matAsset = this.app.assets.find(matName, 'material');
if (matAsset && matAsset.resources && matAsset.resources[0]) {
var modelEntity = this.model;
if (modelEntity && modelEntity.model && modelEntity.model.model) {
if (this.sex === 'M') {
modelEntity.model.model.meshInstances[0].material = matAsset.resources[0];
} else {
modelEntity.model.model.meshInstances[1].material = matAsset.resources[0];
}
}
}
}
// ---- WEAPON 1 ----
enableIfNew.call(this, "WEAPON", this.visualEquip.WEAPON, equip.WEAPON?.obj, this.equip_weapon.bind(this));
// ---- SHIELD 1 ----
enableIfNew.call(this, "SHIELD", this.visualEquip.SHIELD, equip.SHIELD?.obj, this.equip_shield.bind(this));
// ---- WEAPON 2 (BACK) ----
enableIfNew.call(this, "WEAPON2", this.visualEquip.WEAPON2, equip.WEAPON2?.obj, this.secondary_sword.bind(this));
// ---- SHIELD 2 (BACK) ----
enableIfNew.call(this, "SHIELD2", this.visualEquip.SHIELD2, equip.SHIELD2?.obj, this.secondary_shield.bind(this));
// ---- HELM ----
enableIfNew.call(this, "HELM", this.visualEquip.HELM, equip.HELM?.obj, this.equip_helm.bind(this));
};
PlayerRemote.prototype.unequip_tool= function(name) {
this.entity.findByName(name).enabled=false;
};
PlayerRemote.prototype.equip_weapon= function (name,type) {
this.sword=this.entity.findByName(name);
this.rhand = this.model.findByName('Bip01 D Mano');
this.sword.reparent(this.rhand);
if(type==="BLADE" || type==="SWORD" || type==="AXE" || type ==="HAMMER" || type ==="MACE" ) {
this.sword.setLocalPosition(10,-4,-1);
if (name==="axe") {
this.sword.setLocalEulerAngles(100, 0, 180);
} else {
this.sword.setLocalEulerAngles(100, 0, 45);
}
}
if (name==='morningstar') {
this.sword.setLocalEulerAngles(-100, 0, 0);
}
if (name==='waraxe') {
this.sword.setLocalPosition(-6,7,-35);
this.sword.setLocalEulerAngles(100, 20, -10);
}
if(type==='POLE') {
if (name==='spear') {
this.sword.setLocalPosition(27,22,-55);
this.sword.setLocalEulerAngles(120, 0, -35);
}
if (name==='holycane') {
this.sword.setLocalPosition(5,0,0);
this.sword.setLocalEulerAngles(10,10,5);
}
if (name==='rowanstaff'){
this.sword.setLocalPosition(5,0,0);
this.sword.setLocalEulerAngles(-10,20,-90);
}
}
this.wRange=0;
this.wDamage=3;
};
PlayerRemote.prototype.secondary_sword= function (name,two) {
if (two ===false) {
this.sword=this.entity.findByName(name);
this.sheat = this.model.findByName('Bip01 Pelvis');
this.sword.reparent(this.sheat);
this.sword.setLocalPosition(33,26,30);
this.sword.setLocalEulerAngles(0, 45, 120);
} else {
this.sword=this.entity.findByName(name);
this.sheat = this.model.findByName('Bip01 Columna3');
this.sword.reparent(this.sheat);
this.sword.setLocalPosition(70,-18,-22);
this.sword.setLocalEulerAngles(90, -75, 0);
}
};
PlayerRemote.prototype.unequip_sword= function (name) {
this.sword=this.entity.findByName(name);
this.sword.enabled=false;
};
PlayerRemote.prototype.unequip_bow= function (name) {
this.bow=this.entity.findByName(name);
this.bow.enabled=false;
this.pouch.enabled=false;
};
PlayerRemote.prototype.equip_bow= function (name) {
this.bow=this.entity.findByName(name);
this.lhand = this.model.findByName('Bip01 I Mano');
this.bow.reparent(this.lhand);
this.bow.setLocalPosition(5,0,-10);
this.bow.setLocalEulerAngles(90, 180, 0);
this.wRange=7;
this.wDamage=3;
};
PlayerRemote.prototype.secondary_bow= function (name) {
this.bow=this.entity.findByName(name);
this.back = this.model.findByName('Bip01 Columna3');
this.bow.reparent(this.back);
this.bow.setLocalPosition(-20,-20,0);
this.bow.setLocalEulerAngles(90,60,0);
};
PlayerRemote.prototype.equip_helm= function (name) {
this.helm=this.entity.findByName(name);
this.head = this.model.findByName('Bip01 Cabeza');
this.helm.reparent(this.head);
var scale = this.helm.getWorldTransform().getScale();
this.helm.setLocalScale(0.5/scale.x, 0.5/scale.y, 0.5/scale.z);
this.helm.setLocalPosition(1.5,6.5,-0.2);
this.helm.setLocalEulerAngles(-90, -90, 0);
this.helm.enabled=true;
};
PlayerRemote.prototype.equip_shield= function (sname) {
this.shield=this.entity.findByName(sname);
this.lhand = this.model.findByName('Bip01 I Mano');
this.shield.reparent(this.lhand);
this.shield.setLocalPosition(4,-4,-0.2);
this.shield.setLocalEulerAngles(0, 0,190);
if (sname==='pavese' || sname==='pavese1') {
this.shield.setLocalPosition(4,-4,-0.2);
this.shield.setLocalEulerAngles(0, 180,190);
}
if (sname==='towershield' || sname==='phoenixshield') {
this.shield.setLocalPosition(68,6,2);
this.shield.setLocalEulerAngles(180,0,-80);
}
if (sname==='largeshield') {
this.shield.setLocalEulerAngles(0, 180,190);
}
// Magic number that works with the current bone scale
//this.shield.setLocalScale(SHIELD_SCALE_FACTOR, SHIELD_SCALE_FACTOR, SHIELD_SCALE_FACTOR);
this.shield.enabled=true;
};
PlayerRemote.prototype.secondary_shield= function (name) {
this.shield=this.entity.findByName(name);
this.back = this.model.findByName('Bip01 Columna3');
this.shield.reparent(this.back);
this.shield.setLocalPosition(-20,-20,0);
this.shield.setLocalEulerAngles(0, 0, 180);
if (name==='pavese' || name==='pavese1' || name==='largeshield') {
this.shield.setLocalEulerAngles(0, -100,180);
}
if (name==='towershield' || name==='phoenixshield') {
this.shield.setLocalPosition(-70,-25,0);
this.shield.setLocalEulerAngles(0,0,-90);
}
};
//nuovo codice
PlayerRemote.prototype.attachWeapon = function(name) {
// disattiva vecchio
if (this.visualEquip.WEAPON) {
var old = this.entity.findByName(this.visualEquip.WEAPON);
if (old) old.enabled = false;
}
this.visualEquip.WEAPON = name;
var we = this.entity.findByName(name);
if (!we) return;
this.rhand = this.model.findByName('Bip01 D Mano');
we.reparent(this.rhand);
we.setLocalPosition(10, -4, -1);
we.setLocalEulerAngles(100, 0, 45);
we.enabled = true;
};
PlayerRemote.prototype.attachShield = function(name) {
if (this.visualEquip.SHIELD) {
var old = this.entity.findByName(this.visualEquip.SHIELD);
if (old) old.enabled = false;
}
this.visualEquip.SHIELD = name;
var sh = this.entity.findByName(name);
if (!sh) return;
this.lhand = this.model.findByName('Bip01 I Mano');
sh.reparent(this.lhand);
sh.setLocalPosition(4, -4, -0.2);
sh.setLocalEulerAngles(0, 0, 190);
if (name === 'towershield' || name === 'phoenixshield') {
sh.setLocalPosition(68, 6, 2);
sh.setLocalEulerAngles(180, 0, -80);
}
sh.enabled = true;
};
PlayerRemote.prototype.attachWeapon2 = function(name) {
if (this.visualEquip.WEAPON2) {
var old = this.entity.findByName(this.visualEquip.WEAPON2);
if (old) old.enabled = false;
}
this.visualEquip.WEAPON2 = name;
var we = this.entity.findByName(name);
if (!we) return;
this.back = this.model.findByName('Bip01 Columna3');
we.reparent(this.back);
we.setLocalPosition(70, -18, -22);
we.setLocalEulerAngles(90, -75, 0);
we.enabled = true;
};
PlayerRemote.prototype.attachShield2 = function(name) {
if (this.visualEquip.SHIELD2) {
var old = this.entity.findByName(this.visualEquip.SHIELD2);
if (old) old.enabled = false;
}
this.visualEquip.SHIELD2 = name;
var sh = this.entity.findByName(name);
if (!sh) return;
this.back = this.model.findByName('Bip01 Columna3');
sh.reparent(this.back);
sh.setLocalPosition(-20, -20, 0);
sh.setLocalEulerAngles(0, 0, 180);
if (name === 'towershield' || name === 'phoenixshield') {
sh.setLocalPosition(-70, -25, 0);
sh.setLocalEulerAngles(0, 0, -90);
}
sh.enabled = true;
};
PlayerRemote.prototype.attachHelm = function(name) {
if (this.visualEquip.HELM) {
var old = this.entity.findByName(this.visualEquip.HELM);
if (old) old.enabled = false;
}
this.visualEquip.HELM = name;
var he = this.entity.findByName(name);
if (!he) return;
this.head = this.model.findByName('Bip01 Cabeza');
he.reparent(this.head);
var scale = he.getWorldTransform().getScale();
he.setLocalScale(0.5 / scale.x, 0.5 / scale.y, 0.5 / scale.z);
he.setLocalPosition(1.5, 6.5, -0.2);
he.setLocalEulerAngles(-90, -90, 0);
he.enabled = true;
};
PlayerRemote.prototype.applyNetStaticState = function(state) {
if (state.id) this.id = state.id;
if (state.name) this.name = state.name;
if (state.clas) this.clas = state.clas;
let changed = false;
if (state.race && state.race !== this.race) {
this.race = state.race;
changed = true;
}
if (state.sex && state.sex !== this.sex) {
this.sex = state.sex;
changed = true;
}
// IMPORTANTISSIMO: cambia il modello SOLO se cambia race/sex
if (changed) {
this.setModel(this.race, this.sex);
}
};
PlayerRemote.prototype.onPlayerUpdate = function (state) {
if (!state) return;
this.applyNetState(state);
};
my mind is burned can’t find the issue
https://playcanvas.com/project/674858/overview