This is the standard bouncing ball animation . Create a sphere and select it
before running the code. x and y animated only. No errors, just not getting keyframes. ???
I’ve been over and over the formatting too.
def setKeyframes() :
objs = cmds.ls(selection = True) # Grabbing the selected object and assigning variable.
obj = objs[0] # assigning a list to the variable.
yVal = 0 # variable for translate Y attribute
xVal = 0 # variable for translate X attribute
frame = 0 # variable for current frame number
maxVal = 10 # holds objects current height
for i in range(0, 20):
# sets keyframes on both x and y positions
frame = i * 10 # multiplying constant 10 units to frame value.
xVal = i * 2 # multiplying constant 2 units to x value.
# xVal controls how many keyframes created. smaller number more keyframes.
if i % 2 == 1 : # alternate between an ever increasing value(peaks) and 0 (ground).
yVal = 0 # to do this we need to check to see if our loop variable(i) is
# divisible by 2 (%2) = 0 in the case of even numbers and 1 for odd.
# for odd #s set y value to 0.
else:
yVal = maxVal # for even #s set y value to maxVal.
maxVal *= 0.8 # to make the bounce a little less each time we do this.
cmds.setKeyframe(obj + '.translateY', value = yVal, # should create 7 keyframes with a timeline of
time = frame) # 70 frames
cmds.setKeyframe(obj + '.translateX', value = xVal,
time = frame)
setKeyframes() # not getting keyframes