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)?
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 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 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.
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.
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!
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.
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 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?
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:
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 =/
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].