Hi,
I am setting new sprite position every message. But messages are send around 30 times a second (sometimes less if there are lags etc.) and game runs in 60 fps. I want to make movement looks smooth and sprite to not jump between positions. Is there a function to add some linear easing that moves sprite between current pos and new pos?
My code:
NetworkManager.room.onMessage("UserMoved", (message) => {
this.mainNode?.getChildByName(message.userID)?.getChildByName("UserSprite")?.setPosition(new Vec3(message.x, message.y, 0)); // this.mainNode.getChildByName(message.userID)?.getChildByName("UserSprite")?.getPosition().z));
this.mainNode?.getChildByName(message.userID)?.getChildByName("UserName")?.setPosition(new Vec3(message.x, message.y + 55.553, 0)); // this.mainNode.getChildByName(message.userID)?.getChildByName("UserSprite")?.getPosition().z));
this.playerDict.get(message.userID)?.setPosition(this.mainNode?.getChildByName(message.userID)?.getChildByName("UserSprite")?.getPosition().x,this.mainNode?.getChildByName(message.userID)?.getChildByName("UserSprite")?.getPosition().y);
});
When user starts/stops moving walk animation is set on/off with other message:
NetworkManager.room.onMessage("animationChange", (message) => {
if (message.animation != this.playerDict.get(message.userID)?.currentAnimation) {
this.mainNode?.getChildByName(message.userID)?.getChildByName("UserSprite")?.getComponent(Animation)?.crossFade(message.animation, 0.3);
this.playerDict.get(message.userID).currentAnimation = message.animation;
}
});