Hi,
I am new to Urho3D engine and loved it very much. I spent several weeks going through the documentation and examples. I decided to start to create a game using it after that. Now I have a question and could not solve it after trying different methods for several day. I will be really appreciated if anyone could help me
Question:
How to manually slightly adjust one bone during the animation.
More details:
Skeleton: I have a skeleton with ~20 bones, the root bone is “abdomen”, then it’s child bone “spine” which is the root bone of all the upper body bones. The “abdomen” has another two children bones named “thigh.L” and “thigh.R”, which are root bones for all lower body bones.
abdomen
– spine
– thigh.L
– thigh.R
Animations: I have N different sword attack animations for upper body; I have 8 (eight direction) different movement animations for lower body.
Camera: I have a camera following the character (3rd person angle), the character and camera will rotate with the mouse.
We know it’s pretty straightforward to blend upper/lower body animations to create 8*N animation combinations. (I just set lower body animation with layer = 0, and upper body animations with layer = 1, start_bone = “spine”.)
Now it works like this, for example:
If the character is moving towards left. The character node is facing towards left, with the abdomen slightly up and downs during the running animation. Now If I click mouse, the upper body with attack left.
The problem is: I would still need the character to attack the forward (as camera direction in this case). The character attack left because “spine” is a child of “abdomen” and “abdomen” direction is controlled by the running left animation.
My gameplay requires the sword attack/swing direction be exactly the same (only depends on the camera direction) no matter what direction the player is running. Similar to CS, you always aim forward during you press WASD keys.
Things I tried:
- Force the “spine” node to face forward using SetWorldDirection. This does not work good because the character would be very rigid for upper body. The original attack animation, running animation both gives the “abdomen” and “spine” node some up and downs which seems more realistic;
- Get current “spine” direction for each frame of the animation and then rotate it by 90 degrees, set the new direction. This should be the correct solution but I just could not make it work. The whole character just blink a lot, seems like the character is rotating 90 degrees every frame;
- Use IK. I am not very familiar with IK and struggled a lot here. I set the end node IKEffector to “spine” and attach the IKSolver to “abdomen” like this:
// For IK
spine_node_ = node_->GetChild("spine", true);
spine_effector_ = spine_node_->CreateComponent<IKEffector>();
// Control 1 segment to abdomen bone.
spine_effector_->SetChainLength(1);
// For the effectors to work, an IKSolver needs to be attached to one of
// the parent nodes. Typically, you want to place the solver as close as
// possible to the effectors for optimal performance. Since in this case
// we're solving the legs only, we can place the solver at the spine.
abdomen_node_ = node_->GetChild("abdomen", true);
solver_ = abdomen_node_->CreateComponent<IKSolver>();
// Two-bone solver is more efficient and more stable than FABRIK (but only
// works for two bones, obviously).
solver_->SetAlgorithm(IKSolver::ONE_BONE);
// Disable auto-solving, which means we need to call Solve() manually
solver_->SetFeature(IKSolver::AUTO_SOLVE, false);
// solver_->SetFeature(IKSolver::TARGET_ROTATIONS, true);
// Only enable this so the debug draw shows us the pose before solving.
// This should NOT be enabled for any other reason (it does nothing and is
// a waste of performance).
solver_->SetFeature(IKSolver::UPDATE_ORIGINAL_POSE, true);
This just somehow makes my whole character changed, e.g. upside down. Should I expect the “abdomen” bone changes the position using this setting? If the root node of IK chain will change, maybe I should set “spine” as root node? Then there is only one node, there is no chain anymore, how should I make IK change only "spine?
I believe solution 2 should be the correct way to solve it, but I just don’t know how to fix all the details.
BTW:
I’ve been looking for a 3D game engine for a long time and finally found Urho3D. It satisfied all my requirement:
- Light weighted. I’ve used Unity and Unreal for a while, but could not stand those big engines. I don’t need 99% of those stuff but there is no choice. For my 2014 macbook pro, it cannot even run an empty Unreal project fluently, very disappointing.
- Programmer friendly. I don’t like those drag & mouse click operations in editors. It’s very inefficient. I like to see everything including settings in code.
The only drawback for me is the lack of documentation, which I hope will be improved in the near future.