A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [f8] Ball physics

  1. #1
    Junior Member
    Join Date
    Dec 2005
    Posts
    6

    [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.

  2. #2
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    PLZ. What do you mean by this statement:
    Code:
    degrees -= degreesF;
    <signature removed by admin>

  3. #3
    Junior Member
    Join Date
    Dec 2005
    Posts
    6
    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; 05-19-2007 at 05:44 PM.

  4. #4
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    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>

  5. #5
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    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;
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  6. #6
    Junior Member
    Join Date
    Dec 2005
    Posts
    6
    You were right, it was degrees that was the problem. But why is it returning NaN?

  7. #7
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    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

  8. #8
    Junior Member
    Join Date
    Dec 2005
    Posts
    6
    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.

  9. #9
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    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

  10. #10
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    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; 08-19-2007 at 02:25 PM.
    <signature removed by admin>

  11. #11
    Junior Member
    Join Date
    Dec 2005
    Posts
    6
    I have all the gravity and friction declared.
    It's to do with the Y and X declaration.

  12. #12
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center