A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: [CS3] Octopus arms/IK chain movements

  1. #1
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191

    [CS3] Octopus arms/IK chain movements

    I'm curious how I would make something like an octopus or squid with arms made up of several elements, but moving in specified patterns.

    I understand that the "arm" would have different states that it would step into, depending on the scenario. I also understand that it would take something involving kinematics (inverse or forward, I assume) to piece an "arm" together.

    What I'm having problems understanding is how to create these movements via actionscript. Exactly what will tell the "arm" how to move? I know that sin and cos can be used to create something like a wave effect, but what about REALLY specific movements (the arm pulls back and then snaps toward the player)?

    Here's an example of what I'm trying to describe:

    http://youtube.com/watch?v=PdZ3tyW2QfI&feature=related

    Right about the 3:30 mark.


    How would YOU implement such a behavior?
    i'm obsessed with video games.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't think that the effect in the video you linked even uses IK. It looks like it simply has a node at the end of the arm, and a fixed point at the shoulder, then a number of intermediate nodes which are placed according to a specific percentage of the distance between the two. This is easier to calculate, but less "natural" looking.
    If you're really looking for IK, use a physics engine. There are several available, and all of them allow you to link objects together with joints and subject the whole system to various forces.

  3. #3
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191
    Quote Originally Posted by 5TonsOfFlax
    I don't think that the effect in the video you linked even uses IK. It looks like it simply has a node at the end of the arm, and a fixed point at the shoulder, then a number of intermediate nodes which are placed according to a specific percentage of the distance between the two. This is easier to calculate, but less "natural" looking.
    If you're really looking for IK, use a physics engine. There are several available, and all of them allow you to link objects together with joints and subject the whole system to various forces.

    I'm not hellbent on using kinematics, just the solution that's best for my situation.

    Would you care explaining your first method a little more?
    i'm obsessed with video games.

  4. #4
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    I would do a mass/spring kind of system, that uses a tension force between nearest neighbors and a flexion force between next-nearest neighbors. The former gives you a nice distribution when the arm is stretched, the latter gives you a nice curved response when you start slacking the hand back towards the shoulder. Play with the stiffness factors until you get something that looks good.

    You can probably use explicit (euler) integration in time. With just 7-8 masses, you could also look into unconditionally stable integration using the Newmark-Beta method.

    Looks like a fun game

    EDIT: here's a similar effort of my own. It's a tether, not an arm, so its stiffness probably feels all wrong. Drag the box around, fling it with spacebar.

    EDIT2: Thanks for your help a few months ago re: mxml markup, been making some progress with that.
    Attached Files Attached Files

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I'll defer to rachil0 on specific physics simulations. All I was saying was that the effect in the video appeared to not even attempt physics, but rather just redistributed nodes according to a simple formula.

    Let's say you have 5 nodes between the anchor and the end node. You could define them to be at 95, 90, 80, 60 and 30 percent of the way from anchor to end in the y dimesion and evenly space in x. Then apply these percentages to x and y independently to position your nodes each time the end node moves. It's not physics based, but it should give an effect much like the video. The nodes lie along a curve (or line) which is merely scaled according to the bounding box defined by the anchor and end.

  6. #6
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191
    Quote Originally Posted by rachil0
    I would do a mass/spring kind of system, that uses a tension force between nearest neighbors and a flexion force between next-nearest neighbors. The former gives you a nice distribution when the arm is stretched, the latter gives you a nice curved response when you start slacking the hand back towards the shoulder. Play with the stiffness factors until you get something that looks good.

    You can probably use explicit (euler) integration in time. With just 7-8 masses, you could also look into unconditionally stable integration using the Newmark-Beta method.

    Looks like a fun game

    EDIT: here's a similar effort of my own. It's a tether, not an arm, so its stiffness probably feels all wrong. Drag the box around, fling it with spacebar.

    EDIT2: Thanks for your help a few months ago re: mxml markup, been making some progress with that.
    Thanks for the reply, I'm going to take a look at your tether after my lunch break. I didn't even think about using springs, and now that you brought them up, that might actually be the best solution.

    And no problem, regarding the mxml stuff. I've been doing so many Flex projects here at the office lately, it's starting to become second nature. Let me know how that project turns out!
    i'm obsessed with video games.

  7. #7
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    The only complaint I would have with linear interpolation is that when the hand is near the shoulder, all the nodes will clump up on top of one another. I'd prefer them to curl back around to make an "elbow" kind of shape.

    Maybe a compromise solution could be found using bezier curves. Construct a (quadratic) bezier curve using the shoulder and hand positions as the start and end points. For a control point, construct a new point on the perpendicular bisector of the shoulder-hand. The "height" of the control point above the shoulder-hand line depends upon the distance between them - when they are far apart, the control point may be placed very close to the arm. When the hand is closer to the shoulder, the height should be increased - making an elbow shape.

    Then the locations of the nodes can just be interpolated from the bezier curve.

  8. #8
    bibuti. nolen's Avatar
    Join Date
    Sep 2002
    Location
    az.
    Posts
    191
    Quote Originally Posted by 5TonsOfFlax
    I'll defer to rachil0 on specific physics simulations. All I was saying was that the effect in the video appeared to not even attempt physics, but rather just redistributed nodes according to a simple formula.

    Let's say you have 5 nodes between the anchor and the end node. You could define them to be at 95, 90, 80, 60 and 30 percent of the way from anchor to end in the y dimesion and evenly space in x. Then apply these percentages to x and y independently to position your nodes each time the end node moves. It's not physics based, but it should give an effect much like the video. The nodes lie along a curve (or line) which is merely scaled according to the bounding box defined by the anchor and end.
    This makes some sense as well. I'll have to play around with both methods, but I think I'm more familiar with springs.

    The movements would just be applied to the leader node and all the nodes between would just follow naturally, correct? That way I could create a list of movements (or attack patterns) for the arm, which would really just be sets of instructions for the leader node to follow. Right?
    i'm obsessed with video games.

  9. #9
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Quote Originally Posted by rachil0
    I would do a mass/spring kind of system, that uses a tension force between nearest neighbors and a flexion force between next-nearest neighbors. The former gives you a nice distribution when the arm is stretched, the latter gives you a nice curved response when you start slacking the hand back towards the shoulder.
    Interesting thread! Would you care to explain a bit more about the flexion
    force part? What is that? Is it an angular constraint between every other node?
    // Mazapán, my portfolio

  10. #10
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    When using just tension forces with some specific rest length L, any equilibrium solution has every node (point mass) the same distance from the last.

    One equilibrium solution is a straight line (forgive the ascii art):
    Code:
    0    1    2    3    4    5
    |-L--|-L--|-L--|-L--|-L--|
    But another solution, which I find unattractive, is an "accordian fold". It's like a 2D zigzaggy shape:
    Code:
    0    1    
    2    3   
    4    5
    |-L--|
    The flexion springs work pairwise on next-to-nearest masses. They have a rest length of 2L. With these forces, the straight line is still an equilibrium solution:
    Code:
                   |---2L----|
              |---2L----|
         |---2L----|
    |---2L----|
    0    1    2    3    4    5
    |-L--|-L--|-L--|-L--|-L--|
    But the accordian fold is not:
    Code:
    0    1    
    2    3   
    4    5
    |-L--|
    Why? Because the flexion spring between 0 and 2 is in very high compression. It has essentially shrunk to zero length and would be pushing very hard to seperate those nodes. Although it's not coded like an angular constraint, it has similar effects: the flexion spring between 0 and 2 pushes the angle 012 away from zero.

    I feel that adding these additional spring forces makes for a more convincing response when you're trying to simulate a somewhat rigid beam under compressive loads (like a very flexible tent pole). The nearest neighbor forces only give you a good response under tension - under compression you end up with a wet noodle.

    EDIT: ascii art fixup - it's hard to make fixed-width art with a variable-width editor =/
    Last edited by rachil0; 06-13-2008 at 11:26 AM.

  11. #11
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    Reminds me of bricks. You don't build your house like this:

    PHP Code:
    [____][____][____][____][____][____]
    [
    ____][____][____][____][____][____]
    [
    ____][____][____][____][____][____]
    [
    ____][____][____][____][____][____
    you build it like this:

    PHP Code:
    [____][____][____][____][____][____]
    [
    _][____][____][____][____][____][_]
    [
    ____][____][____][____][____][____]
    [
    _][____][____][____][____][____][_

  12. #12
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Ah I see, thanks for explaining! That's very clever!

    edit: A follow-up problem: Is there any easy way to make sure the arm doesn't bend inwards?
    Last edited by Kianis; 06-13-2008 at 02:25 PM.
    // Mazapán, my portfolio

  13. #13
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Hmm, not sure but probably. You could try adding an additional force onto each node, that kicks in when a node encroaches upon the shoulder-hand line. It would be applied perpendicular to that line, so it always bows the arm out in your preferred curvature direction [either z CROSS (hand-shoulder), or z CROSS(shoulder-hand), depending upon the handedness of your coordinate system].

  14. #14
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Yeah, I guess with a bit of tweaking that would look great. Thanks, it was an interesting problem
    // Mazapán, my portfolio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center