How can I get this spider to stick to an animated mesh as it deforms?

I’ve been playing around with the game engine and I want to try using this

What I want to do is import animated obstacles like platforms and wires. I was almost able to this with a basic armature rig that I animated, literally just a mesh and a rig animated in pose mode in the action editor, nothing more.

What I tried is: import the mesh obstacles, select the armature for one them just to test, go to the logic editor, add an always -> and -> action actuator and select the armature’s action and set the proper end frame. When I go to play the game engine, the spider sticks to what is the resting mesh, but it doesn’t move along the deformation of the mesh as the armature moves. How can I get the spider to also follow deformations of the mesh due to its armature?

I feel like this most likely has something to do with dynamic bodies or a collision sensor but I don’t know enough about the game engine to tell what to fix.

If you check physics visualization in game options you’ll see that the physics mesh of the object isn’t updated on armature deform. I’m guessing that’s the problem.

The fix can be a bit tricky, it depends on the complexity of the model and rig. One approach I know of: turning off collision on the display mesh, then create one or several separate invisible ones to serve as a collision mesh instead, then parenting them to the specific bones that control the deformation.

But seriously though if all you need is to move things around or scale them up or down, just don’t use an armature for the obstacles and keyframe transformation values directly instead, that worked last I checked.

I don’t know if I’m understanding what you are suggesting. I copied the mesh and parented it, but all it did was soak up more processing, it didn’t fix the issue. Could you be more specific?

Basic idea:

  1. Create a cube
  2. Make it invisible
  3. Select armature in pose mode
  4. Select the bone
  5. Shift+S->Cursor to selected
  6. Select the cube
  7. Shift+S->Selection to cursor
  8. Adjust position manually if needed
  9. With the cube still selected, shift select the bone in pose mode
  10. Control+P->Parent to bone
  11. Now when the bone moves around, the cube follows
  12. Use the cube to detect collision

You can also use empties.

parent empties to the bones of the armature, move along these.

So you mean no deformation at all, in which case I wouldn’t be using an armature. Something isn’t adding up about what you’re saying because there are many games with things like players floating on wavey water or moving terrain or riding an animal like a horse, so complex deformations aren’t impossible.

And how exactly does parenting an empty to a bone prevent the armature from deforming the mesh? Action plays->mesh deforms – that doesn’t change. You’d just be using objects other than the display mesh itself to simulate the physics.

I reckon one could just call reinstancePhysicsMesh on every tick,
https://docs.blender.org/api/current/bge.types.KX_GameObject.html#bge.types.KX_GameObject.reinstancePhysicsMesh

but it’ll likely mess up your framerate.

What do you exactly want? due to it looks like… i dunno.

You imported the spider, but animations don’t work?

Summary

because as i read the quote i did, to me it looks like you got trouble running the animations?
all animations need to be present on the armature it self, so the Action brick needs to be on the armature in order to play it’s animations.

or

You have spider, but want other things sticking on top of the spider mesh?

Summary

Add an empty on the spot you like to have the rider(on the spider) parent it to a bone below it. Now you need to have a rider without any physics (else you get physics trouble) and just parent it to the empty. Now the rider rides the spider.

You don’t need bones for something like a square platform right? You can just move a square mesh itself up and down and keyframe it, so simple transnational motion isn’t itself the issue. The issue is if you have something that can’t be broken up into discrete pieces that needs to deform smoothly, like wavy water for instance, or a rope or cable, or a fissure opening up in an earthquke, or a tree branch that blows in the wind. What Lie suggested only works for discrete objects that are very simple and mechanical in nature, it wouldn’t work for things that deform smoothly in the way they suggested.

If you can deal with the processor load, you can reinstance the physics mesh (obj.reinstancePhysicsMesh()) whenever a mesh is deformed (eg armature, shapekeys). Warning: a high-end i7 can only manage reinstancing about 5000 polygons per frame. A typical laptop i5 can only handle about 400 polygons per frame.

Better is to use a “trick” such as others have propsed:

  • Interpolate between known points on the armature (eg by attaching an empty to it)
  • Approximate the physics with rigid primitives that are moved rather than deformed.

The approximation work won’t in complex cases. I’ll do what I can to reduce polygons on my own end, but how do I go about doing this reinstance thing? Blender’s manual mentions it a million times, but it doesn’t have the decency to explain it once.
Let’s say I have a mesh called “Mesh,” parented to an armature called “Armature.” What do I do with them?
I tried using this script with an action actuator

import bge

def main():
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
viz = scene.objects[‘Mesh’]
own.reinstancePhysicsMesh(viz)

main()

and it didn’t work.

You shouldn’t need to pass anything into the reinstancePhysicsMesh because you’re updating it rather than replacing it with a new one.

Try:

import bge

def main():
    scene = bge.logic.getCurrentScene()
    cont = bge.logic.getCurrentController()
    own = cont.owner
    viz = scene.objects[‘Mesh’]
    viz.reinstancePhysicsMesh()

main()

Assuming that the object called ‘Mesh’ is the one you want to be updated.
You have to call this script every frame.

Of course, make sure the object uses mesh-type physics bounds.

I get a python script fail, the console says there is an invalid character (even though there’s no special characters at all) and unknown location even though the mesh has the correct name. I also get “Warning, user defined property named “life”” but there’s nothing else in the python script for the game. Then randomly after changing the name of the mesh then back, I get "import error, no module named ‘bge’ "

Instead of using “and,” for the armature controller, I tried using “Python.” When I started the game, now all of a sudden I find the animation isn’t running.

It appears to work in this demo file here in the “Show framerate…” https://docs.blender.org/manual/en/dev/game_engine/physics/introduction.html?highlight=bge%20physics section where it gives a file. The rainbow rectangles animate on their own in game, then they deflect off the wall as their animation deforms it. But for some reason, it doesn’t work in this spider BGE file. I have the same setup where the armature has the always -> and -> action and then for the mesh parented to it, I have always -> python and it doesn’t work, even with the mesh set to dynamic and triangle mesh just like in the demo.
What would even be the point of having triangle mesh bounds if you’re limited to simple squares for collisions?

I think I got it to work by hitting the Pulse mode button in the always actuator. The problem now is that the spider slides off the mesh as the mesh deforms as if it isn’t sticky anymore, where normally the spider would always stick to any mesh at any angle. Could this be related to other physics options like friction? Is there a way to make the detection finer so it doesn’t fling off when the armature moves too fast?

@sdfgeoff I was reading about an nvdidia artical about building bvhtree on the gpu,

do you think a compute shader could stomp out every mesh in a scene at once each frame?

There would be limits, of course. For a few objects, it should be find but not likely for every mesh in the scene. The issue stops being the GPU performance and starts being how long it takes to get the data back on to the CPU for the rest of the calculations. So either you have to have a physics engine running just-on-the-gpu, or you have those constraints.

There is a new class of physics engine slowly making it’s way onto the scene: particle physics engines (such as nVidia flex). They run purely on the GPU, but they aren’t currently suited for general purpose use. They are very good at handling deformations, and I expect them to become more popular over the next few years.

The other thing you may want to look at is the technology behind the game “Shadow of the Colossus” where the main character fights giant creatures he can jump/climb all over. I recall reading an article (or watching a talk) on how it was done, but a quick google didn’t bring me to it.

I think maybe I got it to work by hitting the Pulse mode button in the always actuator. The problem now is that the spider slides off the mesh as the mesh deforms as if it isn’t sticky anymore, where normally the spider would always stick to any mesh at any angle. Could this be related to other physics options like friction? Is there a way to make the detection finer so it doesn’t fling off when the armature moves too fast?

yeah use the empties positions patented to the armature and lerp them.

you are overcomplicating this

What empties? What interpolation?