Got my Spider rig working
You may have seen from my other posts that I have been working on a StepConstraint for a Spider Rig, I have since realized that their is more to making a spider than I first thought:o and a simple constraint is not enough to solve the problem. So I have been working on a full fledged Script to control a Spider/Insect with adaptive step distance and height control.
So you want to see where I’m up to:
I have noticed some poping on the legs >= LegCount/2, any Ideas?
And here is the .Blend
import Blender,BPyWindow,BPyMesh,bpy import math from Blender import * from Blender.Scene import * from Blender.NMesh import * from Blender.Window import * from Blender.Mathutils import * MaxDist = 4.000 SpiderLeg = 'SpiderLeg' MasterName = 'Master' TargetName = 'Target' AverageName = 'Average' AverageBaseName = 'AverageBase' Leg = 0 LegCount = 8 LegName = ['1', '2', '3', '4', '5', '6', '7', '8'] frame=Blender.Get('curframe') activeScene = bpy.data.scenes.active listObject = activeScene.objects ConMaxReached = 0 ConMidReached = 0 XYZMax = 0 while Leg < LegCount: if listObject != None: for obj in activeScene.objects: if Leg < LegCount: if obj.name.endswith(SpiderLeg) == True: ### if obj.name.startswith(MasterName) == True: MasterLegList = obj.name[:-len(SpiderLeg)-1] if MasterLegList.endswith(LegName[Leg]) == True: Master = obj if obj.name.startswith(TargetName) == True: TargetLegList = obj.name[:-len(SpiderLeg)-1] if TargetLegList.endswith(LegName[Leg]) == True: Target = obj if obj.name.startswith(AverageName) == True: if obj.name.startswith(AverageBaseName) == True: AverageBase = obj else: Average = obj if obj.name.startswith(MasterName) == True: MasterLegNo = obj.name[:-len(SpiderLeg)-1] if MasterLegNo.endswith(LegName[Leg]) == True: XMaster,YMaster,ZMaster = Master.getLocation('worldspace') XTarget,YTarget,ZTarget = Target.getLocation('worldspace') XLength = XTarget - XMaster YLength = YTarget - YMaster ZLength = ZTarget - ZMaster XYLength = math.sqrt((XLength*XLength)+(YLength*YLength)) XYZLength = math.sqrt((XYLength*XYLength)+(ZLength*ZLength)) if XYZLength > 0: Target.SizeX = (((XYZLength)*100.00)/(MaxDist*5.00))+1.00 if XYZLength > XYZMax and ConMaxReached == 0 and Leg < LegCount/2: XYZMax = XYZLength if XYZLength > 0: Average.SizeX = (((XYZMax)*100.00)/(MaxDist*5.00))+1.00 if XYZMax > MaxDist/2 and Leg < LegCount/2: ConMidReached = 1 if ConMidReached == 1 and Leg >= LegCount/2 and XYZLength > XYZMax: Target.LocX = XMaster Target.LocY = YMaster Target.LocZ = ZMaster Target.SizeX = 1.00 ###Calcs if the legs if any are at there MaxDist if XYZLength > MaxDist and ConMaxReached == 0 and Leg < LegCount/2: Target.LocX = XMaster Target.LocY = YMaster Target.LocZ = ZMaster Target.SizeX = 1.00 Average.SizeX = 1.00 ConMaxReached = 1 Leg = -1 ###if any of the legs are at there MaxDist Reset if ConMaxReached == 1 and Leg < LegCount/2: Target.LocX = XMaster Target.LocY = YMaster Target.LocZ = ZMaster Target.SizeX = 1.00 Average.SizeX = 1.00 ###Sets the Start Pose if frame == 1: if Leg < LegCount/2: ###For the controle legs Target.LocX = XMaster-(MaxDist/2) if Leg > LegCount/2: ###For the other legs Target.LocX = XMaster Average.LocX = 0 ###For the Average Empty Average.LocY = 0 Average.LocZ = 0 Leg = Leg+1 Blender.Redraw()