|
-
function reacts differently if value passed in as variable and not hard coded
Ok, i have a function that is moving a mc in a spiral.
Here is the code:
Code:
//rotz(dot, 300, 300, .1, 1.004);
rotz(dot, origin_1_x, origin_1_y, .1, 1.004);
function rotz(who,cx,cy,spd,exp){
trace("first x "+who._x);
trace("cx "+cx);
dx = (who._x -cx) * exp;
dy = (who._y -cy) * exp;
trace("dy "+dy);
trace("equation " +(cx+((Math.cos(spd) * dx -(Math.sin(spd) * dy)))));
who._x = cx+((Math.cos(spd) * dx -(Math.sin(spd) * dy)));
who._y = cy+((Math.sin(spd) * dx +(Math.cos(spd) * dy)));
trace("second x "+who._x);
}
right now i have origin_1_x set to 300, so it should act the same as if i had 300 hardcoded (which is currently commented out).
When I hard code 300 in there it works great. but since i will let the user decide what the origin will be, i want to pass a variable instead.
currently, when i hardcode 300 in this is my trace output:
first x 246.95
cx 300
dy -66.3644
equation 253.629273943845
second x 253.6
However, when i pass the variable instead, this is my output
first x 246.95
cx 300
dy -66.3644
equation 300-46.3707260561545
second x 246.95
x gets passed in just fine (as cx is 300), however, the assignment of changing the value of who._x doesn't work at all. and the equation brings back a different result...
anyone else encounter something like this before?
any ideas?
thanks
ty
-
ok, i'm more awake and capable of debugging now, but i am still having problems.
for some reason the variable cx is not getting interpreted
who._x = cx+((Math.cos(spd) * dx -(Math.sin(spd) * dy)));
This comes back
300-46.3707260561545
I've even played with it some like so:
Code:
tempVar = Math.cos(spd) * dx -(Math.sin(spd) * dy);
trace("temp "+tempVar);
trace("cx "+cx);
tempVar + = cx;
trace("new temp" + tempVar);
this returns:
temp -46.3707260561545
cx 300
new temp-46.3707260561545300
Yet, if i change the line
tempVar += cx;
to
tempVar += 300;
then this works fine
i'm really not sure why it's not interpreting cx correctly. And like i said in the first post, when i pass in hardcoded numbers this works fine. but even if i pass in a variable equal to 300 it seems to cause this mess.
anyone have any ideas? i'm really confused.
-ty
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
|