Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics


Create cool 2D games with a free game editor! · By Cosmo Myzrail Gorynych

Moving bones dynamically

A topic by unicitee created May 02, 2019 Views: 70 Replies: 2
Viewing posts 1 to 2
(2 edits)

Is there a way move dynamically a bone from skeletal animation?
I can get a bone with this code:

this.skel = ct.res.makeSkeleton('AnimationName');
var boneIKTarget = this.skel.armature.getBone('BoneName');

But how to change its position? I tried these lines in On Step of a room  but no change appears.

boneIKTarget.boneData.transform.x = ct.mouse.x ;
boneIKTarget.boneData.transform.y = ct.mouse.y ;

Is there a method to transform it?

Thank you for your reply.

Edited :

I found a way to display the new position but I'm always looking for the way to have a precise value. The bone moves but not really at the mouse position.

// we have to add this line to update the new position

We can too change the offset of the bone to modify its position.

boneIKTarget.offset.x = ct.mouse.x - mainIK.boneData.transform.x  ;
boneIKTarget.offset.y = ct.mouse.y - mainIK.boneData.transform.y - ct.height ;

If someone could help.


I haven't tried IK in ct.js, but I may provide some suggestions:.First, try adding this.x and this.y to your math, because skeletons are components of a copy and are positioned relative to it. E.g:

boneIKTarget.offset.x = ct.mouse.x - mainIK.boneData.transform.x - this.x;

If you are rotating your copy, you should handle it as well.

See also examples of DragonBones for pixi.js, they are applicable to ct.js as well: eye tracking and IK as is.

Thank you for you suggestions. It was in the examples of DragonBones for pixi.js that I found the invalidUpdate() function. I'll try your suggestion and continue searching in the DragonBonesJS sources.