Bones position or rotation

Hello, I can’t change the position or rotation of the bone. Where am I making a mistake?

var c= this.app.root.findByName(“character”);
var head=c.model.model.graph.findByName(“head”);
var angles = new pc.Vec3(40,0,0);
head.setLocalPosition(angles);

Is there animation on the entity? Are you getting errors in the console?

1 Like

yes there is animation. When I removed the animation I was able to change the position of the bone. Why can’t I change the position of the bone while there is animation? Do you have a solution? :neutral_face:

The animation is animating the bones so any of your changes from script will get overridden by the animation. It can’t be in two positions at once.

@Elliott is currently reworking the animation system so perhaps this can be supported in the future (have the animation drive some bones and others can be done dynamically in code)

1 Like

thank you @yaustar

Hi @kaandrew. Do you have a project you could share or a little more info on how your character’s animation and script are set up?

Have you also tried updating your character’s position using the scripts postUpdate function rather than update?

1 Like

Oh yes, I didn’t know that. I fixed it with postupdate. I can now change the rotation of the bone, even if it’s animation. Thank you . I wanted to turn the character’s head down when the fps kema looked down, and turn the character’s head up when the fps camera looked up. I’m getting the rotation of the fps camera. But it gives different results in different coordinates. I can’t find the right result.

If my rotation is 60 degrees, I have to turn the character’s head down 60 degrees. This problem also exists in the setEulerAngles function. When I look at the other player in the FPS game, the other player needs to see that I am looking at him.

data.eulerAngles_y=180-data.eulerAngles_y;
var angles = new pc.Vec3(data.eulerAngles_x,data.eulerAngles_y*-1,data.eulerAngles_z);
this.players[data.id].entity.setEulerAngles(angles);

what is it that i miss? I know I am very inadequate in these matters and I am more new.

Without knowing more about the project and how the entities are set up, the camera etc. It’s very difficult to help.

As it’s a multiplayer game, I assume that you are either sending input or position and rotation of all the players in the game. There shouldn’t be much more calculation involved?

If you want, I can add you to the project. Maybe you can say where I made a mistake.