00:00
00:00
Newgrounds Background Image Theme

UmanaJose just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

[AS2] dynamic arm movement

605 Views | 5 Replies
New Topic Respond to this Topic

I feel i'm to dumb for this so imma you guys for some help pls..

I'm trying to make an arm fold, imagine an archer pulling on a bow string, that's what i'm trying to do

heres my test program

http://www.newgrounds.com/dump/item/fade888bdd5edc337d4f02fb7f8f636e

and here's the code

xC = 0; yC = 0;
dist_ = 11.6; dist = dist_;
angle = 0;
onMove = false;
strafe = false;

this.onEnterFrame = function() {

// action

if(strafe && dist>0) { dist -= (dist_*0.20); } else { strafe = false; dist = dist_; }

// animation

if(onMove) { gotoAndStop("run"); } else { gotoAndStop("idle"); }

if(_xmouse < mc._x) { mc._xscale = -100; } else { mc._xscale = 100; }

// bow arm

bA1 = mc.bowArm1; bA2 = mc.bowArm2;

bA1._rotation = Math.atan2(_ymouse-mc._y-bA1._y,_xmouse-mc._x-bA1._x)*(180/Math.PI);

if(mc._xscale == -100) {
bA1._xscale = -100; bA1._yscale = -100;
bA1._rotation = -bA1._rotation;
} else { bA1._xscale = 100; bA1._yscale = 100; }

bA2._rotation = bA1._rotation;

if(mc._xscale == -100) { bA2._xscale = -100; bA2._yscale = -100;
} else { bA2._xscale = 100; bA2._yscale = 100; }

// arrow arm

aA = mc.arrowArm; angle = -bA1._rotation-90;

xD = Math.sin(angle * Math.PI/180)*dist;
yD = Math.cos(angle * Math.PI/180)*dist;

if(mc._xscale == -100) { xC = (mc._x+bA1._x)+xD; yC = (mc._y+bA1._y)+yD;
} else { xC = (mc._x+bA1._x)-xD; yC = (mc._y+bA1._y)-yD; }

aA._rotation = Math.atan2(yC-mc._y-aA._y,xC-mc._x-aA._x)*(180/Math.PI);

// get hypoteneus

px = mc._x+aA._x; py = mc._y+aA._y;
px = (px-Math.abs(xD))*(px-Math.abs(xD)); py = (py-Math.abs(yD))*(py-Math.abs(yD))
hypo = Math.sqrt(px+py); trace(hypo);

// 14 bicep length, 17 for arm length, Hypo

// arrrow arm, arm 1 (bicep)

// aA.arm1 // insert code here

// arrow arm, arm 2 (fore arm)

// aA.arm2 // insert code here

// movement

if(keyDown_W) { _parent._y -= 3; }
if(keyDown_S) { _parent._y += 3; }
if(keyDown_A) { _parent._x -= 3; }
if(keyDown_D) { _parent._x += 3; }

if(keyDown_W || keyDown_S || keyDown_A || keyDown_D) { onMove = true; } else { onMove = false; }

}

//**Player Controls General**//

//control variables
var keyDown_W:Boolean = false; //Up
var keyDown_S:Boolean = false; //Down
var keyDown_A:Boolean = false; //Left
var keyDown_D:Boolean = false; //Right
var keyDown_SPACE:Boolean = false; //Attack

//key listener/detect pressed keys
var playerKeys = new Object();
playerKeys.onKeyDown = function() {

//movement
if(Key.getCode()==87 && !keyDown_W) { keyDown_W = true; keyDown_S = false; }
if(Key.getCode()==83 && !keyDown_S) { keyDown_S = true; keyDown_W = false; }
if(Key.getCode()==65 && !keyDown_A) { keyDown_D = false; keyDown_A = true; }
if(Key.getCode()==68 && !keyDown_D) { keyDown_A = false; keyDown_D = true; }

//attack
if(Key.getCode()==Key.SPACE && !keyDown_SPACE) { keyDown_SPACE = true; strafe = true; }
}
playerKeys.onKeyUp = function() {

//movement
if(Key.getCode()==87) { keyDown_W = false; }
if(Key.getCode()==83) { keyDown_S = false; }
if(Key.getCode()==65) { keyDown_A = false; }
if(Key.getCode()==68) { keyDown_D = false; }

//attack
if(Key.getCode()==Key.SPACE) { keyDown_SPACE = false; }

}
Key.addListener(playerKeys);

Response to [AS2] dynamic arm movement 2015-09-09 11:01:45


my new code

xC = 0; yC = 0;
dist_ = 11.6; dist = dist_;
angle = 0;
onMove = false;
strafe = false;

this.onEnterFrame = function() {
	
	// action
	
	if(strafe && dist>0) { dist -= (dist_*0.15); mc.bowArm2.play();
	} else { strafe = false; dist = dist_; }
	
	// animation
	
	if(onMove) { gotoAndStop("run"); } else { gotoAndStop("idle"); }
	
	if(_xmouse < mc._x) { mc._xscale = -100; } else { mc._xscale = 100; }
	
	// bow arm
	
	bA1 = mc.bowArm1; bA2 = mc.bowArm2;
	
	bA1._rotation = Math.atan2(_ymouse-mc._y-bA1._y,_xmouse-mc._x-bA1._x)*(180/Math.PI);
	
	if(mc._xscale == -100) {
		bA1._xscale = -100; bA1._yscale = -100; 
		bA1._rotation = -bA1._rotation;
	} else { bA1._xscale = 100; bA1._yscale = 100; }
	
	bA2._rotation = bA1._rotation;
	
	if(mc._xscale == -100) { bA2._xscale = -100; bA2._yscale = -100; 
	} else { bA2._xscale = 100; bA2._yscale = 100; }
	
	// arrow arm
	
	aA = mc.arrowArm; angle = -bA1._rotation-90;
	
	xD = Math.sin(angle * Math.PI/180)*dist;
    yD = Math.cos(angle * Math.PI/180)*dist;
	
	if(mc._xscale == -100) { xC = (mc._x+bA1._x)+xD; yC = (mc._y+bA1._y)+yD;
	} else { xC = (mc._x+bA1._x)-xD; yC = (mc._y+bA1._y)-yD; }
	
	//aA._rotation = Math.atan2(yC-mc._y-aA._y,xC-mc._x-aA._x)*(180/Math.PI);
	
	// get hypoteneus / triangle base
	
	px = mc._x+aA._x; py = mc._y+aA._y;
	px = (px-Math.abs(xD))*(px-Math.abs(xD)); py = (py-Math.abs(yD))*(py-Math.abs(yD))
	base = Math.sqrt(px+py); trace(base);
	
	// shoulder to elbow length, fore arm length, hypotenuse
	
	a = 14; b = 18; c = base;
	
	// arrrow arm, arm 1 (shoulder to elbow)
	
	degrees = ((Math.acos((a*a + c*c - b*b) / (2*a*c)))*(180/Math.PI))-90; //trace(degrees);
	
	aA.arm1._rotation = degrees;
	
	// arrow arm, arm 2 (fore arm) 
	
	aA.arm2._x = Math.sin(-aA.arm1._rotation * Math.PI/180)*14;
    aA.arm2._y = Math.cos(-aA.arm1._rotation * Math.PI/180)*14;
	
	aA.arm2._rotation = Math.atan2(yC-mc._y-aA._y-aA.arm2._y,xC-mc._x-aA._x-aA.arm2._x)*(180/Math.PI);
	aA.arm2._rotation -= 90; //
	
	// movement
	
	if(keyDown_W) { _parent._y -= 3; } if(keyDown_S) { _parent._y += 3; }
	if(keyDown_A) { _parent._x -= 3; } if(keyDown_D) { _parent._x += 3; }
	
	if(keyDown_W || keyDown_S || keyDown_A || keyDown_D) { onMove = true; } else { onMove = false; }
	
}

//**Player Controls General**//

//control variables
var keyDown_W:Boolean = false; //Up
var keyDown_S:Boolean = false; //Down
var keyDown_A:Boolean = false; //Left
var keyDown_D:Boolean = false; //Right
var keyDown_SPACE:Boolean = false; //Attack

//key listener/detect pressed keys
var playerKeys = new Object();
playerKeys.onKeyDown = function() {
	
	//movement
	if(Key.getCode()==87 && !keyDown_W) { keyDown_W = true; keyDown_S = false; }
	if(Key.getCode()==83 && !keyDown_S) { keyDown_S = true; keyDown_W = false; }
	if(Key.getCode()==65 && !keyDown_A) { keyDown_D = false; keyDown_A = true; }
	if(Key.getCode()==68 && !keyDown_D) { keyDown_A = false; keyDown_D = true; }
	
	//attack
	if(Key.getCode()==Key.SPACE && !keyDown_SPACE) { keyDown_SPACE = true; strafe = true; }
}
playerKeys.onKeyUp = function() {
	
	//movement
	if(Key.getCode()==87) { keyDown_W = false; }
	if(Key.getCode()==83) { keyDown_S = false; }
	if(Key.getCode()==65) { keyDown_A = false; }
	if(Key.getCode()==68) { keyDown_D = false; }
		
	//attack
	if(Key.getCode()==Key.SPACE) { keyDown_SPACE = false; }
	
}
Key.addListener(playerKeys);

Response to [AS2] dynamic arm movement 2015-09-09 12:48:25


I don't really know what happens in mc.bowArm2.play(); - Do you have the result?
Another solution would be mc.bowArm2.gotoAndStop("draw");
And mc.bowArm2.gotoAndStop("release"); when space is released for smooth animations.

I was going to suggest make custom animations when I saw the first code. No matter where you aim the draw-back arm should always end up at the same place. (Upper chest area-ish) Since the distance from the hand on the second arm to that point is always the same, it would be acceptable to have a fixed animation.


At 9/9/15 12:48 PM, Maxiecole wrote: I don't really know what happens in mc.bowArm2.play(); - Do you have the result?
Another solution would be mc.bowArm2.gotoAndStop("draw");
And mc.bowArm2.gotoAndStop("release"); when space is released for smooth animations.

I was going to suggest make custom animations when I saw the first code. No matter where you aim the draw-back arm should always end up at the same place. (Upper chest area-ish) Since the distance from the hand on the second arm to that point is always the same, it would be acceptable to have a fixed animation.

here's the updated flash bro:

http://www.newgrounds.com/dump/item/9c0e25934a57aae7503e5e52de273c84

it plays an animation with the bow

now the only weird thing is when you move the cursor below the player and the pulling arm make a weird angle.. well, i think it's better than the pinwheeling arms with some of my earlier code

Response to [AS2] dynamic arm movement 2015-09-09 22:18:28


so, anybody know how to fix this wrong angle when the cursor is below the player?

Response to [AS2] dynamic arm movement 2015-09-09 22:58:38


here's the code i'm gonna use

xC = 0; yC = 0;
dist_ = 11.6; dist = dist_;
angle = 0;
onMove = false;
strafe = false;

this.onEnterFrame = function() {
	
	// action
	
	if(strafe && dist>0) { dist -= (dist_*0.15); mc.bowArm2.play();
	} else { strafe = false; dist = dist_; }
	
	// animation
	
	if(onMove) { gotoAndStop("run"); } else { gotoAndStop("idle"); }
	
	if(_xmouse < mc._x) { mc._xscale = -100; } else { mc._xscale = 100; }
	
	// bow arm
	
	bA1 = mc.bowArm1; bA2 = mc.bowArm2;
	
	bA1._rotation = Math.atan2(_ymouse-mc._y-bA1._y,_xmouse-mc._x-bA1._x)*(180/Math.PI);
	
	if(mc._xscale == -100) {
		bA1._xscale = -100; bA1._yscale = -100; 
		bA1._rotation = -bA1._rotation;
	} else { bA1._xscale = 100; bA1._yscale = 100; }
	
	bA2._rotation = bA1._rotation;
	
	if(mc._xscale == -100) { bA2._xscale = -100; bA2._yscale = -100; 
	} else { bA2._xscale = 100; bA2._yscale = 100; }
	
	// arrow arm
	
	aA = mc.arrowArm; angle = -bA1._rotation-90;
	
	xD = Math.sin(angle * Math.PI/180)*dist;
    yD = Math.cos(angle * Math.PI/180)*dist;
	
	if(mc._xscale == -100) { xC = (mc._x+bA1._x)+xD; yC = (mc._y+bA1._y)+yD;
	} else { xC = (mc._x+bA1._x)-xD; yC = (mc._y+bA1._y)-yD; }
	
	//aA._rotation = Math.atan2(yC-mc._y-aA._y,xC-mc._x-aA._x)*(180/Math.PI);
	
	// get hypoteneus / triangle base
	
	px = mc._x+aA._x; py = mc._y+aA._y;
	px = (px-Math.abs(xD))*(px-Math.abs(xD)); py = (py-Math.abs(yD))*(py-Math.abs(yD));
	base = Math.sqrt(px+py); //trace(base);
	
	// shoulder to elbow length, fore arm length, hypotenuse
	
	a = 15; b = 18; c = base;
	
	// arrrow arm, arm 1 (shoulder to elbow)
	
	degrees = ((Math.acos((b*b + c*c - a*a) / (2*b*c)))*(180/Math.PI))-90;
	
	if(_ymouse > _parent._y) { degrees = -degrees-90; } //trace(degrees)
	
	aA.arm1._rotation = degrees;
	
	// arrow arm, arm 2 (fore arm)
	
	aA.arm2._x = Math.sin(-aA.arm1._rotation * Math.PI/180)*14;
    aA.arm2._y = Math.cos(-aA.arm1._rotation * Math.PI/180)*14;
	
	aA.arm2._rotation = Math.atan2(yC-mc._y-aA._y-aA.arm2._y,xC-mc._x-aA._x-aA.arm2._x)*(180/Math.PI);
	aA.arm2._rotation -= 90; //
	
	// movement
	
	if(keyDown_W) { _parent._y -= 3; } if(keyDown_S) { _parent._y += 3; }
	if(keyDown_A) { _parent._x -= 3; } if(keyDown_D) { _parent._x += 3; }
	
	if(keyDown_W || keyDown_S || keyDown_A || keyDown_D) { onMove = true; } else { onMove = false; }
	
}

//**Player Controls General**//

//control variables
var keyDown_W:Boolean = false; //Up
var keyDown_S:Boolean = false; //Down
var keyDown_A:Boolean = false; //Left
var keyDown_D:Boolean = false; //Right
var keyDown_SPACE:Boolean = false; //Attack

//key listener/detect pressed keys
var playerKeys = new Object();
playerKeys.onKeyDown = function() {
	
	//movement
	if(Key.getCode()==87 && !keyDown_W) { keyDown_W = true; keyDown_S = false; }
	if(Key.getCode()==83 && !keyDown_S) { keyDown_S = true; keyDown_W = false; }
	if(Key.getCode()==65 && !keyDown_A) { keyDown_D = false; keyDown_A = true; }
	if(Key.getCode()==68 && !keyDown_D) { keyDown_A = false; keyDown_D = true; }
	
	//attack
	if(Key.getCode()==Key.SPACE && !keyDown_SPACE) { keyDown_SPACE = true; strafe = true; }
}
playerKeys.onKeyUp = function() {
	
	//movement
	if(Key.getCode()==87) { keyDown_W = false; }
	if(Key.getCode()==83) { keyDown_S = false; }
	if(Key.getCode()==65) { keyDown_A = false; }
	if(Key.getCode()==68) { keyDown_D = false; }
		
	//attack
	if(Key.getCode()==Key.SPACE) { keyDown_SPACE = false; }
	
}
Key.addListener(playerKeys);