
[f8] Ball physics
Code:
if(hitTest(_root.ball))
{
Y = _y  ball._y;
X = _x  ball._x;
root = Math.atan2(Y, X);
degrees = root /(Math.PI/180);
YF = _y + gravity;
XF = _x * friction;
root = Math.atan2(YF, XF);
degreesF = root /(Math.PI/180);
degrees = degreesF;
yvol = (degrees  0.090) * 100;
xvol = (degrees  0.180) * 100;
}
Why is it that xvol/yvol doesn't want to use degrees? It turns to NaN by the end.

When in doubt ask
PLZ. What do you mean by this statement:
Code:
degrees = degreesF;
<signature removed by admin>

I added that because I think thats how I can get the physics of it to work. I have tried alot, this is really one of the tests.
Last edited by e8newallm4; 05192007 at 05:44 PM.

When in doubt ask
This code shows error when compiled:
Code:
var degeesF=100;
var degrees;
degrees = degreesF;
trace(degrees );
Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Operator '' must be followed by an operand
trace(degrees );
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: ')' or ',' expected
Total ActionScript Errors: 2 Reported Errors: 2
<signature removed by admin>

All 1s and 0s
Hi,
The statement 'degrees = degreesF' is perfectly validI don't think EBeaver recognises the '=' operator.
You should insert trace statements to find out when exactly degrees becomes NaN:
code:
root = Math.atan2(Y, X);
degrees = root /(Math.PI/180);
trace(degrees) //Does this return NaN?
YF = _y + gravity;
etc., until you find the line of code that is causing the error. If you're still stuck, post back.
XF = _x * friction;
"If I have seen further, it is by standing on the shoulders of giants."  Sir Isaac Newton

You were right, it was degrees that was the problem. But why is it returning NaN?

All 1s and 0s
Hi,
Try tracing root as well:
code:
root = Math.atan2(Y, X);
trace(root);
Still a problem? If so, try tracing Y and X until you find the root of the problem.
"If I have seen further, it is by standing on the shoulders of giants."  Sir Isaac Newton

It's to do with the Y and X. When I tried adding a different feature a few seconds ago, which included maths also, it didn't work. I think it's the "Math." thats screwing up.

All 1s and 0s
Hi,
I've never heard of Math 'screwing up'. Have you tried tracing Y and X?
code:
trace("Y: " + Y + "; X: " + X);
"If I have seen further, it is by standing on the shoulders of giants."  Sir Isaac Newton

When in doubt ask
The code seems to work after declaring the variables gravity, and friction, and adding: onEnterFrame=function(){ statement.
here is the modified code
Code:
var gravity=0.9;
var friction=0.9;
onEnterFrame=function(){
if(hitTest(_root.ball)) {
Y = _y _root. ball._y;
X = _x  _root.ball._x;
root = Math.atan2(Y, X);
degrees = root /(Math.PI/180);
YF = _y + gravity;
XF = _x * friction;
root = Math.atan2(YF, XF);
degreesF = root /(Math.PI/180);
degrees = degreesF;
yvol = (degrees  0.090) * 100;
xvol = (degrees  0.180) * 100;
trace(yvol/xvol);
}
}
Also please see the attached FLA (F8).
Last edited by Eager Beaver; 08192007 at 02:25 PM.
<signature removed by admin>

I have all the gravity and friction declared.
It's to do with the Y and X declaration.

All 1s and 0s
Hi,
Lol, I think I see the problem:
code:
Y = _y  _root.ball._y;
X = _x  _root.ball._x;
Hope this helps.
"If I have seen further, it is by standing on the shoulders of giants."  Sir Isaac Newton
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
