- #1
MadAce
- 2
- 1
- TL;DR Summary
- Position a game physics object in certain position using angular velocity
I apologize for messy title, but that's as short as I could make it to say all that I wanted.
I also apologize if I'm not using correct math phrases, but I'll try to picture a problem the best I can.
I've been pulling my hair out trying to solve a problem I'm having for couple of months.
The problem:
This is regarding a mod I'm trying to make for a game (Fallout: New Vegas).
I need to find a way to set character's ragdoll limbs into a specific pose using a function that sets an angular velocity to a specific bone on a character.
This function sets (local or worldspace) angular velocity on X, Y and Z axis on any rigid body that is affected by game's physics engine.
Angular velocity in this case is a unit of 2π rad/s or revolutions/second. So if every in-game frame I'm setting velocity on X axis to 5, it will keep rotating that physical rigid object at 5 revs/sec until I stop calling that function while still being affected by other phyical properties like gravity.
Note: This is the only function that's letting me do any kind of rotation of a physical body in game.
What I have currently:
I have an invisible game object that is a copy of character skeleton where I have all animations stored.
Via function I get current local rotation of a bone (it returns X, Y, Z Euler angles) on that invisible skeleton, for example Upper right arm bone (I'll call that variable Anim).
I do the same, but for physical bone on a character ragdoll (variable name Rag).
Then I do the following to get needed angular velocity:
fAngVelX = (fAnimRotX - fRagRotX)
fAngVelY = (fAnimRotY - fRagRotY)
fAngVelZ = (fAnimRotZ - fRagRotZ)
I put those values into function that adds angular velocity to a physical object.
Basically, I'm trying to copy rotation from an animated invisible bone to a physical bone.
And this very simple solution worked. Well, I thought it worked. The solution seemed way too easy.
Problem is clearly visible in this video:
Green "barrel" thingies are the physical bodies, while red ones are static (not affected by game's physics engine). At rest, all rotations are 0, 0, 0 and everything seems to work fine. When I try to set red object to some pose, at the beginning everything seems fine until I reach certain angles at which green body starts going crazy.
I'm sure it's got something to do with how Euler angles work since angles go from 0 to 180 and then jump to -180 and go back to 0 if you keep rotating in the same direction. I also have option to convert Eulers to Quaternions and vice versa, but... Good Lord.
Is there a solution to this issue and is it even possible to do the thing I need with functions I have available?
I'd highly appreciate an answer since it's been bothering me for so long.
And sorry for a long post!
I also apologize if I'm not using correct math phrases, but I'll try to picture a problem the best I can.
I've been pulling my hair out trying to solve a problem I'm having for couple of months.
The problem:
This is regarding a mod I'm trying to make for a game (Fallout: New Vegas).
I need to find a way to set character's ragdoll limbs into a specific pose using a function that sets an angular velocity to a specific bone on a character.
This function sets (local or worldspace) angular velocity on X, Y and Z axis on any rigid body that is affected by game's physics engine.
Angular velocity in this case is a unit of 2π rad/s or revolutions/second. So if every in-game frame I'm setting velocity on X axis to 5, it will keep rotating that physical rigid object at 5 revs/sec until I stop calling that function while still being affected by other phyical properties like gravity.
Note: This is the only function that's letting me do any kind of rotation of a physical body in game.
What I have currently:
I have an invisible game object that is a copy of character skeleton where I have all animations stored.
Via function I get current local rotation of a bone (it returns X, Y, Z Euler angles) on that invisible skeleton, for example Upper right arm bone (I'll call that variable Anim).
I do the same, but for physical bone on a character ragdoll (variable name Rag).
Then I do the following to get needed angular velocity:
fAngVelX = (fAnimRotX - fRagRotX)
fAngVelY = (fAnimRotY - fRagRotY)
fAngVelZ = (fAnimRotZ - fRagRotZ)
I put those values into function that adds angular velocity to a physical object.
Basically, I'm trying to copy rotation from an animated invisible bone to a physical bone.
And this very simple solution worked. Well, I thought it worked. The solution seemed way too easy.
Problem is clearly visible in this video:
Green "barrel" thingies are the physical bodies, while red ones are static (not affected by game's physics engine). At rest, all rotations are 0, 0, 0 and everything seems to work fine. When I try to set red object to some pose, at the beginning everything seems fine until I reach certain angles at which green body starts going crazy.
I'm sure it's got something to do with how Euler angles work since angles go from 0 to 180 and then jump to -180 and go back to 0 if you keep rotating in the same direction. I also have option to convert Eulers to Quaternions and vice versa, but... Good Lord.
Is there a solution to this issue and is it even possible to do the thing I need with functions I have available?
I'd highly appreciate an answer since it's been bothering me for so long.
And sorry for a long post!