I have a technical question.
Let's say I want to create an environment with an event for example:
- a man kicking a ball
Can I control the physics of the scene?
I would like to define the ball's velocity as 10m/sec.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Yes, you can access almost all properties with python. Activate the python tooltips, which make it easy to find the name of a property.
I'd use the technique from this answer.
With that, the object will start beeing a rigidbody on frame three. And the rigid body system will use its velocity from frame 2, which we define with our location keyframes. A script to achieve this is at the end of this answer.
(Reference for keyframing rigid body properties of multiple objects.)
The passive rigid body collision objects are setup manually, but can be coded just as well.
The finished script:
import bpy import mathutils ball = bpy.data.objects['Ball'] # select the ball and make it a rigid body tutorial ball.select = True bpy.context.scene.objects.active = ball bpy.ops.rigidbody.object_add() # Set the rigid bodies properties ball.rigid_body.collision_shape = 'SPHERE' ball.rigid_body.friction = 0.6 ball.rigid_body.restitution = 0.4 ball.rigid_body.use_margin = True # Get the first frame of the scene, or whenever # the ball is supposed to start moving, and the fps. # Also set the interpolation to linear. start_frame = bpy.context.scene.frame_start fps = bpy.context.scene.render.fps pref_edit = bpy.context.user_preferences.edit keyInterp = pref_edit.keyframe_new_interpolation_type pref_edit.keyframe_new_interpolation_type ='LINEAR' # setup the start position and the velocity # the velocity is in units/second/fps*2 start_position = ball.location velocity = mathutils.Vector((1, 0, .5)).normalized() * 10 / fps * 2 # keyframe the start_position on the first frame # and the moved ball on the next frame ball.location = start_position ball.keyframe_insert(data_path='location', frame=start_frame) ball.location = start_position + velocity ball.keyframe_insert(data_path='location', frame=start_frame+2) ball.rigid_body.kinematic = True ball.keyframe_insert(data_path='rigid_body.kinematic', frame=start_frame + 1) ball.rigid_body.kinematic = False ball.keyframe_insert(data_path='rigid_body.kinematic', frame=start_frame + 2) # set interpolation type back pref_edit.keyframe_new_interpolation_type = keyInterp