2
$\begingroup$

I am having trouble finding an example of how to use python scripts to drive shape keys, as opposed to using python scripts to move bones which animate the characters mesh through Bone Driven Shape Key animations. In other words - is there a way of changing the shape key values in the BGE during game play that is simper than accessing the bones which are tied (using Drivers) to the shape keys values? Here is an example of Bone Driven Shape Key animations http://vimeo.com/21357304 if it is not clear what I am referring to (go to 15:20 on-wards). Thanks guys!

$\endgroup$
2
$\begingroup$

I don't see a way of accessing the shape key value from within the game engine. A mesh object is copied to a KX_MeshProxy for use in the game engine, which only gives access to the mesh and materials. This would mean that we need to use either drivers or actions to animate shape keys within the game engine.

If you have a driver setup that uses the bone position to control the shape key then you need to move the bone to control the shape key. You can create an action that moves the bone and can easily be played in the game engine.

Without using a driver you can create an action that keyframes the shape key value and then play that action in the game engine. Use the Shape Key Editor instead of the Action Editor (both are subtypes of the Dope Sheet). Shape Key actions show up in the same list as normal actions.

If you don't want to play an action from start to finish then you will want to have a driver that simply sets the shape key value to an object's X location. You can add an empty just for this purpose and move it in small increments to set the shape key value to the value you want at the time you want it there.

$\endgroup$
  • $\begingroup$ Thanks for the insight. It is not possible then to perhaps create a Game Property, whose value can be changed in a script called from a BGE Logic Brick, and which is linked to the x-axis of the Driver graph for a Shape Key? In the Drivers drop down list in the properties of the Graph Editor/Drivers panel there is the option to "Add Variable". There is the option to change the Driver Variable Type, for example to Single Property. It then needs a path, can this path not link to the Game Property variable being changed in the BGE script called by the Logic Block? $\endgroup$ – CubeBot88 Mar 26 '14 at 8:30
  • $\begingroup$ We can only access limited data within the bge. I think if you want fine control based on events you need to use a driver on the shape key value, it could be as simple as value=empty.location.x and you can change the empty's location by 0.001 to get the shape key value you want. $\endgroup$ – sambler Mar 27 '14 at 6:08
  • $\begingroup$ Thanks sambler. Here is a link I found in my research that might help others too: link. The best solution can be found in the infiniteShapeKeyDemo.blend file posted by MarcoIT. Their solution is basically what you just stated above. But I was hoping that since 2011 they may have updated the BGE to have more access to controlling the characters animations/shape keys. $\endgroup$ – CubeBot88 Mar 27 '14 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.