 A Flash Developer Resource Site

1. ## [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.  Reply With Quote

2. PLZ. What do you mean by this statement:
Code:
`degrees -= degreesF;`  Reply With Quote

3. 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.  Reply With Quote

4. 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  Reply With Quote

5. Hi,

The statement 'degrees -= degreesF' is perfectly valid---I 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;  Reply With Quote

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

7. 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.  Reply With Quote

8. 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.  Reply With Quote

9. Hi,

I've never heard of Math 'screwing up'. Have you tried tracing Y and X?

code:
```
trace("Y: " + Y + "; X: " + X);
```  Reply With Quote

10. 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).  Reply With Quote

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

12. Hi,

Lol, I think I see the problem:

code:
```
Y = _y - _root.ball._y;
X = _x - _root.ball._x;
```

Hope this helps.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 