Hi All!
So! We’re making this campaign ad for a client. It should have some Balloons i.e. one peice of helium balloon and a string attached to it. You should be able to drag the string and the balloon should follow it, if you release it it should head upwards. Well, you get it. It’s a freaking balloon!
I’ve been able to create the ballon and attached a string to it using som forward kinematics stuff, my problem though is to apply the gravity to the string itself and how the make the string behave correctly when dragging it…
here’s my code sofar
package {
import flash.display.*;
import flash.events.*;
import flash.geom.Point;
public class setTail extends MovieClip {
private var tWidth:Number;
private var tHeight:Number;
private var ta:Number;
private var segments:Array = new Array();
private var headTarget:MovieClip;
private var vx:Number = 0;
private var vy:Number = 0;
/*
private var friction:Number;
private var spring:Number;
private var gravity:Number;
*/
public function setTail(t:MovieClip) {
//headTarget is the Ballon, it has all the gravity and movement stuff, the Tail just follows it.
headTarget = t;
/*
friction = headTarget._friction;
spring = headTarget._spring;
gravity = headTarget._gravity
*/
tWidth = headTarget.tailWidth;
tHeight = headTarget.tailHeight;
ta = headTarget.tailNum;
//generate the Tails
setupTails();
}
private function setupTails():void {
//make the ballon the first object in the tail array
segments.push(headTarget);
//add segments
for (var i:Number = 0; i < ta; i++) {
var c:Segment = new Segment(tWidth, tHeight, 0xc19f4f);
addChild(c);
segments.push(c);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
//set i to 1 so that we'll skip the balloon mc.
for (var i:uint = 1; i < segments.length; i++) {
//get the tailsegments
var segmentA:MovieClip = segments*;
var segmentB:MovieClip = segments[i - 1];
//make som movement!
drag(segmentA, segmentB.x, segmentB.y);
}
}
private function drag(segment:MovieClip, xpos:Number, ypos:Number):void {
var dx:Number = xpos - segment.x;
var dy:Number = ypos - segment.y;
var angle:Number = Math.atan2(dy, dx);
segment.rotation = angle * 180 / Math.PI;
/*
There should be somekind of gravity applied here but I can't figure it out...
I tried adding:
segment.vy += gravity;
but that just drags the tile apart....
*/
//getPin returns a Point
var w:Number = segment.getPin().x - segment.x;
var h:Number = segment.getPin().y - segment.y;
segment.x = xpos - w;
segment.y = (ypos += segment.vy) - h;
}
}
}