|
-
file not found
need another pair of eyes
I've been working on a segment of code for the past few days now for a game, somethings wrong, but I can't tell what.
I have a line drawn between two mc's, and based on how the length of that line changes (it's rotated from mc2 to mc1), I want the distance between the two to change as well.
so...
mc2
|\
|..\c
|....\
|......\mc1
when "c" changes, mc1 should move accordingly.
What am I doing wrong?
Code:
for (j; j<1; j++) {
var a = mc1._y - foot2._y;
var b = mc1._x - foot2._x;
var c = Math.sqrt(a*a+b*b);
}
c = mc2._height;
a = c*Math.sin(point);
b = Math.sqrt(c*c-a*a);
mc1._x = mc2._x+b;
mc1._y = mc2._y+a;
-or-
can you tell me a better, entirely different way of doing this?
Last edited by Captain_404; 08-08-2006 at 10:50 AM.
-
Wait- what now?
what exactly happens and what doesnt happen. Can you post the fla up here because i dont get whether you are using flash drawing API etc,etc.
-
file not found
I would, but it's about 125 kb to big, and that's after cutting down on not-neccisary stuff and compacting. sorry.
it's not done using a drawing api, it's done based on the changing height of a mc.
Code:
for (j; j<1; j++) {
var a = mc1._y - foot2._y;
var b = mc1._x - foot2._x;
var c = Math.sqrt(a*a+b*b);
mc2._height = c;
}
first part loops once, sets "a" and "b" = to the x/y distance between the first mc and anoother sort of base mc (foot2)
more code that I just changed in it recently makes mc2._height = c
Code:
c = mc2._height;
a = c*Math.sin(point);
b = Math.sqrt(c*c-a*a);
mc1._x = mc2._x+b;
mc1._y = mc2._y+a;
//EDIT: point is the angle that mc2 is pointed.
this is the part that's not working
it makes c = mc2._height so that when I change mc2 height, everything else changes
which is done by
a = c*Math.sin(point);
b = Math.sqrt(c*c-a*a);
tracing brings up stuff like:
c=775.45
a=0
b=775.45
then it moves mc1 to be equal to the x/y of mc2 + the changed x/y distance
obviously, there's something wrong with how "a" is calculated, but I'm at my wits end here.
EDITx2:
I discovered there was nothing wrong with the code I was looking at, the whole problem is that mc2 isn't rotating right...
Code:
MovieClip.prototype.pointAt = function(x,y) {
var dx = x - this._x; // distance to other object on x-axis
var dy = y - this._y; // distance on y-axis
var dist = Math.sqrt(dx*dx + dy*dy); // true distance (using Pythagorean theorem)
var angle;
// figure out angle in radians (0- 2*PI)
if (dy <0)
angle = Math.PI*2-Math.acos(dx/dist);
else
angle = Math.acos(dx/dist);
// convert to rotation value (angle in degrees or 0-360)
this._rotation = angle*180/Math.PI;
}
I got this somewhere and I was using it, it worked for a while.
on mc2:
onClipEvent (enterFrame) {
this.pointAt(this._parent.mc1._x, this._parent.mc1._y);
}
Last edited by Captain_404; 08-08-2006 at 12:35 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|