Jump to content

Scene neither loading on Sandbox nor on index.html file


Recommended Posts

but i have one confusion that if i increase the restitution than i guess it will just increase the bounce of the ball not the speed. rather than restitution i think applyimpulse function will work more properly like i shown below .... don't you think that?? 

 if (evt.keyCode === 76) {
                    sphere.physicsImpostor.applyImpulse(new BABYLON.Vector3(0, 4, 2), sphere.getAbsolutePosition());
                    //  r2.restitution += 0.1;
                if (evt.keyCode === 67) {
                    sphere.physicsImpostor.applyImpulse(new BABYLON.Vector3(0, -4, -2), sphere.getAbsolutePosition());
                    //r1.restitution += 0.1;


I am waiting for your reply... :)

Link to comment
Share on other sites


Increasing the racquet restitution... will cause the physics engine to add more magnitude to the ball linearVelocity FOR YOU.  Don't add more restitution to the ball.  ONLY to the paddles (if boost key is held).

Notice the BABYLON.Vector3(0, 4, 2) above?  That is a direction with magnitude.  Do you see that it is the same direction as BABYLON.Vector3(0, 2, 1)?  (It is.)  Do you see that it is the same direction as BABYLON.Vector3(0, 1, 0.5)?  Sure you do.  Direction vectors are strange, eh?  They are different from rotations and positions.  They are like a "pointing arrow", with adjustable arrow length.  :)

SO... BABYLON.Vector3(0, 4, 2) === BABYLON.Vector3(0, 1, 0.5) directionally-speaking, but it is 4 times more magnitude.  (Same direction but more "power")  :)

Now, do you know... at WHAT ANGLE... the ball will hit the paddle?  No.  So you don't know what direction to impulse the ball... to give it more speed, right?  If you could measure angle of ball impact AT impact-time, then perhaps you could write a formula to determine the direction that the ball should LEAVE the paddle... and add/create impulse in that correct direction and at boosted magnitude.  "Boosted magnitude" would be a calculation of ball speed (just before impact)... plus boost amount. 

See what I am saying?  To find the direction of boost/brake... you must get ball speed and ball flight-angle... just before impact.  Possibly difficult.

Okay, option two.  Let the physics engine do normal impact and rebound angle/speed.  Then, immediately AFTER the ball has departed the paddle, add or subtract magnitude to/from the CURRENT linearVelocity.  Let the physics engine calculate the impact and rebound direction FIRST, and then, when the physics engine sets its NEW linearVelocity (for ball departure)... then query that value... and increase/decrease its magnitude.  But don't change its direction.  JUST the magnitude.

To increase magnitude, multiply all non-zero values in the linearVelocity... * 1.05.  To decrease, multiply * .95  (example values).  But, for easiest and best results, this must happen immediately after ball rebound from a paddle/racket/racquet.  :)  This allows the physics engine to FIRST complete its ball bounce direction/speed settings... which were derived by using the ball impact angle and speed.

Or... try it with paddle impostor change-out, or on-the-fly paddle impostor restitution adjusting, like I described earlier.  Might work.  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...