I have a rocket based off of some data of its real-world acceleration. The acceleration is changing at an inconstant rate. So for every second (24 frames in my situation) I want to update my rocket's acceleration in python. The only way I have thought of it being possible is keyframing gravity, but I have no idea how to do that in blender python.
-
$\begingroup$ Are you trying to simulate the rocket's path using a physics simulation? If so, your acceleration is a force that you're applying to the rocket, and you can keyframe the value of the force. $\endgroup$– Marty FoutsCommented Feb 16, 2022 at 0:33
-
$\begingroup$ Where would you get acceleration as a force, and how would you keyframe it? $\endgroup$– Thomas0100Commented Feb 19, 2022 at 17:01
-
$\begingroup$ While you answered the nuts and bolts of the question, the spirit of the question begs the question of why not just key-framing a force-field's force... $\endgroup$– KirbinatorCommented Feb 20, 2022 at 18:04
-
$\begingroup$ In my scenario, I needed to align the objects acceleration with external data. Unfortunately, force fields aren't measured in newtons, as far as I'm aware. Essentially what I'm trying to say is that force fields won't work for me because I can't convert force field units to newtons, and back to acceleration. Even if I could, I believe just changing the acceleration to the data is much simpler. $\endgroup$– Thomas0100Commented Feb 20, 2022 at 20:47
1 Answer
Fixed the issue, it seems that through scripting, we can change the gravity (acceleration) variable at certain frames. In my situation, I wanted to switch gravity at every second, therefore, every 24 frames. So it would look like
C = bpy.context
def my_handler(scene):
if C.scene.frame_current % 24 == 0:
C.scene.gravity[2] = currentAccList[int(C.scene.frame_current/24)]
Essentially, for every second, we update our acceleration from a list. In my situation, that list is rocket acceleration data. C.scene.gravity[2] represents acceleration in the Z axis (up, down). Another useful tip, if you want to have the simulation and gravity set beforehand, this reference helps:
-
$\begingroup$ You might want to add additional context, right now as written the force will be set to zero on the 24th frame and stay zero (and if that's what you want, why not just >= 24?) $\endgroup$ Commented Feb 20, 2022 at 18:05
-
$\begingroup$ Updated it, hopefully it makes more sense. $\endgroup$ Commented Feb 20, 2022 at 20:52