this is my code.
input.addListener({
down: (x, y) => {
startX = x;
startY = y;
mouse.set(x, canvas_1.clientHeight - y, 0)
var bestDistance = 50,
index = 0;
var best;
var set_render =renderer.camera.screenToWorld(coords.set(x, y, 0), canvas_1.clientWidth, canvas_1.clientHeight);
for (var i = 0; i < controlbones.length; i++) {
hoverTargets[i] = null;
let bone = skeleton.findBone(controlbones[i]);
var position = new spine.Vector2(bone.length, 0);
bone.localToWorld(position);
let distance = renderer.camera.worldToScreen(
coords.set(bone.worldX, bone.worldY, 0),
canvas_1.clientWidth, canvas_1.clientHeight).distance(mouse);
// let distance = Math.sqrt((coords.x - bone.x) * (coords.x - bone.x) + (coords.y - bone.y) * (coords.y - bone.y));
if (distance < bestDistance) {
bestDistance = distance;
best = bone;
index = i;
}
}
if (best) hoverTargets[index] = best;
target = best;
},
up: (x, y) => {
target = null;
},
dragged: (x, y) => {
currentX = x;
currentY = y;
const distanceX = currentX - startX;
const distanceY = currentY - startY;
hair_distance = Math.sqrt(distanceX ** 2 + distanceY ** 2);
if (30 < hair_distance) {
dragged(canvas_1, renderer, target, x, y);
}
}
})
function dragged(canvas_1, renderer, target, x, y){
if (target) {
x = spine.MathUtils.clamp(x, 0, canvas_1.clientWidth);
y = spine.MathUtils.clamp(y, 0, canvas_1.clientHeight);
dragX = x;
dragY = y;
var newX = startX + 0.25*(dragX - startX);
var newY = startY + 0.25*(dragY - startY);
renderer.camera.screenToWorld(coords.set(newX, newY, 0), canvas_1.clientWidth, canvas_1.clientHeight);
if (target.parent !== null) {
target.parent.worldToLocal(position.set(coords.x, coords.y));
target.x = position.x;
target.y = position.y;
} else {
target.x = coords.x;
target.y = coords.y;
}
}
}
}
The code to move the armature is the same as the example.
There is no bouncing if you move the bone outside of the hairless area. However, if you move the skeleton to the inside where the hair is, bouncing occurs.
When moving with a very short touch, the problem is coming out. Is there any way to fix this?