[MX04] Ragdoll Engine - Need Help
hi, i have recently started trying to figure out a ragdoll engine and was wondering if anybody out there could please tell me;
how to add a second player's ragdoll (that would be a different colour so that they could battle)
and also how to change the colour of the ragdolls both to begin with, eg player 1: black, player 2: dark grey, and during the movie, aka. if player 1 got a metal suit powerup that reduces damage done to him, that it would change his colour to be light grey instead of black.
here is the code i am using... please ask if you need any more information about what i am trying to achieve.
Code:
function Vector(x, y) {
this.x = x;
this.y = y;
this.length = Math.sqrt(x*x+y*y);
}
function constrain(p0, p1, l) {
var correction = 0.025000;
var dx = p1._x-p0._x;
var dy = p1._y-p0._y;
var d = new Vector(dx, dy);
var r = (d.length-l)/d.length;
var x = d.x*0.500000*r;
var y = d.y*0.500000*r;
p1._x = p1._x-(x-correction);
p1._y = p1._y-y;
p0._x = p0._x+(x+correction);
p0._y = p0._y+y;
}
function update() {
var p;
var i = 0;
while (i<joints.length) {
this[joints[i]].update();
i++;
}
}
function collisions() {
var p;
var x;
var y;
var c = false;
var i = 0;
while (i<joints.length) {
p = this[joints[i]];
if (p.collisions()) {
c = true;
x = p._x;
y = p._y;
}
i++;
}
if (c) {
if (!soundplaying) {
var sbreak = new Sound(this);
sbreak.onSoundComplete = function() {
soundplaying = false;
};
var rand = random(4);
var pan = -100+head._x*200/445;
sbreak.attachSound("break"+rand);
sbreak.start(0, 0);
sbreak.setVolume(75);
sbreak.setPan(pan);
soundplaying = true;
}
drawblood(x, y);
}
}
function constraints() {
var i = 0;
while (i<2) {
constrain(lhand, lelbow, 12);
constrain(lelbow, neck, 12);
constrain(rhand, relbow, 12);
constrain(relbow, neck, 12);
constrain(neck, waist, 20);
constrain(lknee, waist, 20);
constrain(lfoot, lknee, 20);
constrain(rknee, waist, 20);
constrain(rfoot, rknee, 20);
constrain(head, neck, 3.500000);
i++;
}
}
function setup() {
constraints();
var p;
var i = 0;
while (i<joints.length) {
p = this[joints[i]];
p.lx = p._x;
p.ly = p._y;
i++;
}
}
function drawblood(x, y) {
var b;
var i = 0;
while (i<=random(3)+3) {
b = attachMovie("Blood", "Blood"+blooddepth, blooddepth++);
b._x = x;
b._y = y;
i++;
}
}
function drawhead(col) {
var cx = 0;
var cy = 0;
var r = 7;
head.beginFill(col == undefined ? (0) : (col), 100);
head.moveTo(cx+r, cy);
var a = 0;
while (a<=6.283185) {
head.lineTo(cx+Math.cos(a)*r, cy+Math.sin(a)*r);
a = a+0.069813;
}
head.endFill();
}
function draw(col) {
clear();
lineStyle(5, col == undefined ? (0) : (col), 100);
moveTo(lhand._x, lhand._y);
lineTo(lelbow._x, lelbow._y);
lineTo(neck._x, neck._y);
lineTo(relbow._x, relbow._y);
lineTo(rhand._x, rhand._y);
moveTo(neck._x, neck._y);
lineTo(waist._x, waist._y);
lineTo(lknee._x, lknee._y);
lineTo(lfoot._x, lfoot._y);
moveTo(waist._x, waist._y);
lineTo(rknee._x, rknee._y);
lineTo(rfoot._x, rfoot._y);
var dx = neck._x-head._x;
var dy = neck._y-head._y;
head._rotation = Math.atan2(dy, dx)*180/3.141593;
}
function onEnterFrame() {
update();
constraints();
collisions();
draw(ragdollcolor);
}
MovieClip.prototype.useHandCursor = false;
var dragging = null;
var blooddepth = 0;
var soundplaying = false;
var ragdollcolor = 0;
var joints = new Array("lhand", "lelbow", "rhand", "relbow", "neck", "waist", "lknee", "lfoot", "rknee", "rfoot", "head");
drawhead(ragdollcolor);
setup();
stop();