0
$\begingroup$

I'm trying to create a simulation in blender of a person walking.

I did a program to advance one leg 1 degree (and return the other 1 deg) after pressing the space bar but I can't see the advance while the game is executing and instead of that, I see the movement until I stop the game. I think it could be because of the pose mode. But I'm not sure. No error is displayed in the console while executing.

I attach some pictures and the code:

  1. Before running the game: 1. Before running the game:

  2. While running the game nothing moves. 2. While running the game nothing moves.

  3. When I stop it after pressing the "space bar" few times and it leaves the executing screen it appears it what I think is the final position, but nothing happens while executing. enter image description here

  4. Logic Editor: enter image description here

  5. Code:

    import math import bpy import numpy as np import bge from bge import logic

    controller = logic.getCurrentController() own = controller.owner

    sensors=own.sensors

    CODE PART 1. ROTATION

    ob = bpy.data.objects['Armature'] bpy.context.scene.objects.active = ob bpy.ops.object.mode_set(mode='OBJECT')

    rhip = ob.pose.bones['Thigh.R'] rleg = ob.pose.bones['Leg.R'] rfoot= ob.pose.bones['Foot.R']

    lhip = ob.pose.bones['Thigh.L'] lleg = ob.pose.bones['Leg.L'] lfoot= ob.pose.bones['Foot.L']

    Set rotation mode to Euler XYZ, easier to understand

    than default quaternions

    rhip.rotation_mode = 'XYZ' rleg.rotation_mode = 'XYZ' rfoot.rotation_mode = 'XYZ' lhip.rotation_mode = 'XYZ' lleg.rotation_mode = 'XYZ' lfoot.rotation_mode = 'XYZ'

    select axis in ['X','Y','Z'] <--bone local

    axis = 'Z' actual_angle = [0,0,0,0,0,0]

    def refresh_angle(): global actual_angle lecture=[1,1,1,-1,-1,-1] angle=np.array(lecture)-np.array(actual_angle)

    rhip.rotation_euler.rotate_axis(axis, math.radians(angle[0]))
    rleg.rotation_euler.rotate_axis(axis, math.radians(angle[1]))
    rfoot.rotation_euler.rotate_axis(axis, math.radians(angle[2]))
    lhip.rotation_euler.rotate_axis(axis, math.radians(angle[3]))
    lleg.rotation_euler.rotate_axis(axis, math.radians(angle[4]))
    lfoot.rotation_euler.rotate_axis(axis, math.radians(angle[5]))
    
    actual_angle=angle
    

    if sensors["Spacebar"].positive: refresh_angle()

$\endgroup$
0
$\begingroup$

While in the related question i test channel.location.x += 0.1 and channel.location.x += 0.1 but none work all time print (0,0,0) (i try because i never has move a bone), so i read the armature documentation and location. Finally end up with this script.

from bge import logic

armature = logic.getCurrentController().owner
if not hasattr(logic, 'boneLocation'):
    logic.boneLocation = 0
else:
    logic.boneLocation += 0.5
    channel = armature.channels["moveBone.003"]
    channel.location = [logic.boneLocation, 0, 1]
    print(channel.location)
    logic.getCurrentController().owner.update()

Blender Game Engine Started <Vector (0.5000, 0.0000, 1.0000)> <Vector (1.0000, 0.0000, 1.0000)> <Vector (1.5000, 0.0000, 1.0000)> <Vector (2.0000, 0.0000, 1.0000)> <Vector (2.5000, 0.0000, 1.0000)> <Vector (3.0000, 0.0000, 1.0000)> <Vector (3.5000, 0.0000, 1.0000)> <Vector (4.0000, 0.0000, 1.0000)>

$\endgroup$
  • $\begingroup$ Thank you very much. The above code its just working for me for translation and not rotation; it doesn't move the full chain of bones like if it where in pose mode. Did you know one way to move one bone by rotation in some quantity of degrees with implicit movement of the full chain of bones?. Reading Armature I think joint_rotation could work, but I have no idea how to implement it. $\endgroup$ – Juan Dec 6 '17 at 17:58
  • $\begingroup$ I would like to help you while i learn how to do it but i am really busy and that may need a lot of time. Also i don't have a single minimum armature to start testing. I made the above just with one bone $\endgroup$ – Strapicarus Dec 6 '17 at 23:20

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.