我想用 python 在 Blender 中制作一个 Side Scroller。有人可以向我解释一下为什么这个脚本不起作用吗?
import bge
def main():
cont = bge.logic.getCurrentController()
player = cont.owner
scene = bge.logic.getCurrentScene()
keyboard = bge.logic.keyboard
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DKEY]:
player.localPosition.x += 0.1
elif bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.AKEY]:
player.localPosition.x += -0.1
elif bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.WKEY]:
player.localPosition.z += 0.5
main()
import bpy
import math
# Clear existing objects
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
# Create base mesh
bpy.ops.mesh.primitive_cylinder(radius=1, depth=2, location=(0, 0, 0))
# Access the newly created cylinder object
obj = bpy.context.active_object
# Scale the cylinder to create the body proportions
obj.scale = (0.5, 0.5, 1.5)
# Apply scale to avoid issues with further modifications
bpy.ops.object.transform_apply(scale=True)
# Subdivide the mesh for smoother deformation
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.subdivide(number_cuts=6)
bpy.ops.object.mode_set(mode='OBJECT')
# Apply smooth shading
bpy.ops.object.shade_smooth()
# Rename the object
obj.name = "Draculaura_Body_Base"
# Create shape keys for further modifications
bpy.ops.object.shape_key_add(from_mix=False)
# Rename the first shape key to "Basis"
obj.data.shape_keys.key_blocks[0].name = "Basis"
# Add shape key for adjusting proportions
bpy.ops.object.shape_key_add(from_mix=False)
# Rename the second shape key to "Proportions"
obj.data.shape_keys.key_blocks[1].name = "Proportions"
# Set up Draculaura-like proportions (you may need to adjust these values)
proportions_key = obj.data.shape_keys.key_blocks["Proportions"]
for v in obj.data.vertices:
if v.co.z > 0.5:
v.co *= 1.1 # Adjust upper body
else:
v.co *= 0.9 # Adjust lower body
# Example: Add wings, you can customize further based on your requirements
bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 2.5))
wings_obj = bpy.context.active_object
wings_obj.scale = (0.2, 0.2, 0.2)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.subdivide(number_cuts=2)
bpy.ops.object.mode_set(mode='OBJECT')
wings_obj.name = "Wings"
wings_obj.parent = obj
# Select the main object
bpy.context.view_layer.objects.active = obj
obj.select_set(True)