Triggering Animation based on change in x Position

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 30/10/2011 at 16:25, xxxxxxxx wrote:

Hi Everyone,

I'm very new to Python on C4D, but I'm sure what I'm trying to do is possible with Python.

Basically, I have a sprite that is composed of three objects - an animation of an 8bit character walking.

I have the code working in an XPresso node so far that I'm able to switch the character's state based on User Data, but I would really like to trigger the walk cycle depending on how much the character has moved on X. Something like if last position has changed on x by five, switch to next state and so on.

I know that will have to do with Vectors and Time, but I'm a little lost as to where to start.

-SP

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/10/2011 at 03:32, xxxxxxxx wrote:

if you want user data to change depending on how much the character has moved so far, it would be possible with xpresso, too.
But its more comfortable through scripting though. :)

``````states = [0, 100, 200, 300]     # units on the x-axis
# the indices of the values represent
# the state of the userdata for this value

def **getState** (x_pos) :
if x_pos < states[0]:
return 0

for i in xrange(len(states) - 1) :
if x_pos >= states[i] and x_pos < states[i + 1]:
return i + 1

if x_pos >= states[-1]:
return len(states)
else:
pass
# should never run until here !.

for i in xrange(-100, 500, 120) :
print ("State at x-position %s:" % i).ljust(30, "."), getState(i)
``````
``````State at x-position -100:..... 0
State at x-position 20:....... 1
State at x-position 140:...... 2
State at x-position 260:...... 3
State at x-position 380:...... 4
``````

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/10/2011 at 14:46, xxxxxxxx wrote:

Thanks for the reply!

That is a great solution, but what I'm looking for I think is even simpler. I basically have three frames that will loop depending on how far on X the character has moved.

What I need is some way of storing how much the character has moved on X. To do this, I need to test the change over time, and the c4d.BaseTime module is very unwieldy. It looks like I might need to store a frame number, from the documentation.

Is there a simple way to check for change in X over a certain amount of time?

• THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 31/10/2011 at 15:31, xxxxxxxx wrote:

Is there a simple way to check for change in X over a certain amount of time?

Course,

``````class _container:
pass
data = _container()
data.last_x_pos = 0

def main() :
pos = op.GetAbsPos().x
delta = pos - data.last_x_pos
#....
data.last_x_pos = pos
``````