Make character body bend dynamically

Currently in my fps game, I am working on networking, and I realized that my soldiers were missing something. And that is the lack of ability for other players to see where they are aiming (vertically). If you notice in fps gams, when a player aimes up, the players back bends to show where they are looking. When it comes to my project, I have no clue how I could go about doing this. If anyone has any ideas that would be sweet!

What I’ve seen on the internet included procedural animation controls where you animate the up and down aiming and simply pick a frame based on what the angle is but I don’t know if that is possible or the best solution in jme

I’m glad you brought this up. I’m not there yet in my project, but will have to address this also. All I can contribute with is to discuss my planned approach (which may or may not be the best way).

I’m expecting I will need to find the Bones used in the rig (and animations) from blender and rotate them programatically. See TestCustomAnim.java in the docs/demo project.

If you think of something more clever, I’ll sure be happy to hear it

You CAN bend joints individually without creating an animation, but the procedure is non-obvious. (I do this for head rotation in the game I’m writing.)

You start by finding the character’s SkeletonControl using Spatial.getControl(). Invoke control.getSkeleton() to access the skeleton and skeleton.getBone() to access the bone you want to manipulate. Before you can manipulate the bone directly, however, you need to invoke
[java]bone.setUserControl(true);[/java]
(You only have set it once.)

Once that’s done, you can invoke bone.setUserTransforms() to alter the position, orientation, and scaling of the bone – typically you only want to change the orientation, so the invocation looks like
[java]setUserTransforms(Vector3f.ZERO, orientation, Vector3f.UNIT_XYZ);[/java]

The orientation is of course a Quaternion, which is tricky to get right.

1 Like
@sgold said: You CAN bend joints individually without creating an animation, but the procedure is non-obvious. (I do this for head rotation in the game I'm writing.)

You start by finding the character’s SkeletonControl using Spatial.getControl(). Invoke control.getSkeleton() to access the skeleton and skeleton.getBone() to access the bone you want to manipulate. Before you can manipulate the bone directly, however, you need to invoke
[java]bone.setUserControl(true);[/java]
(You only have set it once.)

Once that’s done, you can invoke bone.setUserTransforms() to alter the position, orientation, and scaling of the bone – typically you only want to change the orientation, so the invocation looks like
[java]setUserTransforms(Vector3f.ZERO, orientation, Vector3f.UNIT_XYZ);[/java]

The orientation is of course a Quaternion, which is tricky to get right.


Thanks for the feedback! I can use the up vector of the camera to justify what my vertical angle is and find some constant where I can see the z value of the rotation to that. And yes, quats always are a hassle at first and takes me a while to get them right haha.

@sgold said: You CAN bend joints individually without creating an animation, but the procedure is non-obvious. (I do this for head rotation in the game I'm writing.)

You start by finding the character’s SkeletonControl using Spatial.getControl(). Invoke control.getSkeleton() to access the skeleton and skeleton.getBone() to access the bone you want to manipulate. Before you can manipulate the bone directly, however, you need to invoke
[java]bone.setUserControl(true);[/java]
(You only have set it once.)

Once that’s done, you can invoke bone.setUserTransforms() to alter the position, orientation, and scaling of the bone – typically you only want to change the orientation, so the invocation looks like
[java]setUserTransforms(Vector3f.ZERO, orientation, Vector3f.UNIT_XYZ);[/java]

The orientation is of course a Quaternion, which is tricky to get right.

The question I have would be whether this will affect the animations that I would be playing

I believe the user transform is applied on top of any animations, but I’m not sure. Perhaps someone else knows.

@finnjohnsen said: I'm glad you brought this up. I'm not there yet in my project, but will have to address this also. All I can contribute with is to discuss my planned approach (which may or may not be the best way).

I’m expecting I will need to find the Bones used in the rig (and animations) from blender and rotate them programatically. See TestCustomAnim.java in the docs/demo project.

If you think of something more clever, I’ll sure be happy to hear it


I’m not sure if you got sgold’s reply, but yes, rotating programmatically is what you have to do

1 Like
@Jmonkier said: I'm not sure if you got sgold's reply, but yes, rotating programmatically is what you have to do

Ye thanks. Keep us posted on your progress! :slight_smile:

1 Like
@finnjohnsen said: Ye thanks. Keep us posted on your progress! :)
=D well today was a massive breakthrough for me. I've only looked into networking 3 days ago (at the chat test) and today I just finished the ability for many players to join a map and the other players can see them aim, crouch, jump, walk, with all the animations associate. I also got rays for shooting to work. If you go to YouTube here http://youtu.be/nbr06mFWfl8 you can see what the "single player" portion looks like. However I have added a lot since then. It is more of an engine in the vid but id appreciate it if you all give some feedback and constructive criticism!
2 Likes

Looks fine to me — not that I know much about FPSs.

Wow, that looks really nice! Can’t wait to see things develop more!