Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Triggering Animation based on change in x Position

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 499 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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.

      Thanks in Advance,

      -SP

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post