Missing animation when using Bullet Engine

I’m able to make gravity using either ForceNode

gravity_force_node = ForceNode("world-forces")

gravity_force_node_path\
= self.application.render.attachNewNode(gravity_force_node)

gravity_force = LinearVectorForce(0, 0, -9.81)
gravity_force_node.addForce(gravity_force)
base.physicsMgr.addLinearForce(gravity_force)

or with Bullet World

self.application.world.setGravity(Vec3(0, 0, -9.81))

Both of these work for creating gravity, but when I try to make my cubes rotate and fall using Bullet Engine they only fall, but no animation.

Here’s the code for the Actors

shape = BulletBoxShape(Vec3(1, 1, 1))
node = BulletRigidBodyNode('Box')
np = self.application.render.attachNewNode(node)

node.setMass(1.0)
node.addShape(shape)

np.setPos(0, 0, 10)
self.application.world.attachRigidBody(node)
model = Actor('data/objects/rotating_cube', {'rotate': 'data/objects/rotating_cube_rotate'})
model.flattenLight()
model.reparentTo(np)

Hmm… I see two potential problems:

First, and least likely I feel, I don’t see a call to either of the “play” or “loop” methods. However, I’m guessing that this likely happens outside of this snippet.

More concerning is that your Actor seems as though it may be stored in a local variable–that is, “model” as opposed to something like “self.model”. If I recall correctly, Actors don’t work properly if you don’t keep a reference of your own to them (just parenting them to another node isn’t enough).

If I have that correct, and this code takes place within a method, try storing the Actor in a non-local variable, such as within an instance of a class.

Yep, you’re right about it not working without self. But why? It’s not like it’s out of scope, it’s like 1 or 2 steps from when it was first created. It’s almost like the function isn’t looking at the Actor object itself being referenced, but at the object the Actor object is being referenced from?

???

But as soon as you exit that method, after starting the animation, the variable goes out of scope–and that, I think, is the problem for an Actor. The animation having been started prior to falling out of scope doesn’t prevent this, I think.

I’m not sure of the specifics offhand, I’m afraid–perhaps one of the others will have more insight–but it’s a known issue with Actors that if they go out of scope, they stop working properly, if I recall correctly.

I believe when the Actor falls out of scope, it will stop updating animations. So, you can play the animation and may be a frame in, but then the animation will “stop” because it is no longer getting updated.