   Motion of model by code
  I have a model of a soldier in format .xMy game is in 3D platform like booster trooper:If you look at the video, the character's arms move up and down according to the crosshair (mouse)I am wanting to do something, but I have no idea how to move the arms of my character by codeI'm using DirectX and C++   
  Heya,There are several techniques to doing this but I'll tell you how I like to do it (:But first, do you know how to do skeletal animation?  Also, do you know how to blend between multiple animations?If not that is a pre-requisite and something you want to learn.Anyways... What I would do in this situation is split the body into upper body and lower body bone groups.This makes it so you can play a different animation on the lower body than the upper body - ie the lower body can crouch, run and jump while the upper body can aim, shoot and reload.Next up, for the upper body aiming, let's assume the player is just idling ie their upper body is just aiming, not shooting or reloading or anything.I'd make 3 upper body animations for the "aiming" state.  One pointed straight up, one pointed straight ahead, and one pointed straight down.Calculate the angle that the player is aiming and convert it into a percent - IE if they were pointing 45 degrees upwards, they would be pointing 50% upwards.What you would do then is play the straight forward animation on the upper body, along with the straight up animation which you would blend in 50% of the way.As the player points their gun higher, the % they are pointing vertical becomes higher and so the amount you blend in the pointing up animation becomes higher too.When you are pointed up 100% of the way up, all you see is the pointing up animation.  When you are pointed up 0% of the way, all you see is the pointing forward animation.  When you are between 0% and 100% you see a blend of the 2 which makes it look like the player is able to smoothly point up or down.BTW you just do the mirror of this for pointing downwards and blend in the pointing down animation instead of the pointing up animation.Essentially you are ALWAYS playing the pointing forward animation, and from there you figure out which animation to blend into it (the up or down pointing one) and how much to blend them (based on how high or low the player is aiming).Also, if you have other animations such as firing and reloading, you would make the 3 animations for each of those as well (forward, up and down).Hope this helps, let me know if you are confused about any of this and I can try and elaborate.   ;  Well, until the party to split the model into the top and bottom, I understand.after that I got confused   ;  No need to "split" anything. However, you need to be familiar with how your code updates the bone matrices, usually done once per frame by multiplying it by its parent's matrix.In your model, determine which "bone" moves the arm (a bone is just a matrix). As the user moves the mouse, determine the angle to rotate the arm. That will probably be based on the bone's world position in relation to the target (apparently moved by the mouse). Multiply the bone matrix by a rotation matrix based on the determined angle before you multiply it by it's parent's matrix.You may have to take into consideration the parent's rotation.   ;  How can I control the bones in format .x?   ;  Is your "soldier" x-file an animated model?If not, you'll have to create one.If you're working in 2D, a much easier alternative is just to use sprites rather than a 3D model - a sprite for the body and a sprite for the arm (or quads with transparent textures).   ;  "No need to "split" anything."Good luck when you want to play a lower body animation separately from the upper body animation! :P;  Yes, my soldier is a animated modelis model 3d, my game is 3DAstrix256 try to explain again? I got confusedI look my model (with wordpad) Frame Bip01_Head {    FrameTransformMatrix {0.979719, 0.200374, -0.000001, 0.000000,-0.200374, 0.979719, 0.000000, 0.000000,0.000001, 0.000000, 1.000000, 0.000000,4.443601, 0.000000, 0.000000, 1.000000;;    }   }   Frame Bip01_L_Arm {    FrameTransformMatrix {-0.069033, -0.001290, -0.997614, 0.000000,0.018641, -0.999826, 0.000003, 0.000000,-0.997440, -0.018596, 0.069045, 0.000000,0.000004, 0.003534, -1.732721, 1.000000;;    }    Frame Bip01_L_Arm1 {FrameTransformMatrix { 0.998888, 0.004094, -0.046963, 0.000000, -0.005302, 0.999658, -0.025617, 0.000000, 0.046842, 0.025837, 0.998568, 0.000000, 6.384776, 0.000000, -0.000001, 1.000000;;}They are the bones of the model, right?There is no way to control the bones of the arm by code? would be much easierthanks   ;Quote:Atrix256 said: Good luck when you want to play a lower body animation separately from the upper body animation! :PYou don't need separate animations for upper and lower body. The arm is animated as desired when the final bone matrices for the animation is being calculated each frame during whatever animation is being played - jumping, running, standing still, etc.@VitaliBR:Yep, that looks like an animated model.At some point in your code for animating the model, you should be calculating final bone matrices each frame, before you render the animation (however you do that). In that calculation loop, you would modify the rotation of the arm as desired.EDIT: The result will be similar to what Atrix256 is describing, only you'll only need one rather than 3 animations for each movement type (running, jumping,...).   ;  Can bones be moved in code (i.e how do games like half life haveanimations but can move the head from side to side seemingly seperateto the main animation)?   