Jump to content

Reset Ball after Falling Down


Recommended Posts

Hi Guys, 

I followed the eBook to create this super monkey ball game. When the ball fell off the cliff or spiked by the spikes, it will be reset to the start position with a height of 5, then it will drop and rest on the block. Oimo.js is used as the physics engine. Below is my reset function:

   Player.prototype.reset = function(pos){
     this.directions = [0,0];
     this.rotations = [0,0];
     this.position = pos;
     this.position.y = Player.START_HEIGHT;

      this.rotation = BABYLON.Vector3.Zero();

My question/issue is: After falling down the cliff, and resetting the ball, the ball will not be upside up sometimes. i.e. when I push it to go forward, it will jump up instead. When I rotate it to left, it will rotate to right. Do you have any idea about this issue?


Thank you very much.



Link to comment
Share on other sites

Hi guys!  Welcome aboard, Robin!

In my opinion, this line is not necessary or useful:   this.rotation = BABYLON.Vector3.Zero();

When a mesh gets a physics impostor, it no-longer uses its Euler .rotation property/value.

Instead, it uses the swell .rotationQuaternion property/value.

Soooo... I think if you replace your last line... with this:

this.rotationQuaternion = BABYLON.Quaternion.Zero();

...then there will be dancing in the streets.  Give her a try.  Report back, if you would.  thx.

Link to comment
Share on other sites

this.rotationQuaternion = BABYLON.Quaternion.Zero();

I tried the code above, but it does not work. A purple screen will be displayed forever. I do not quite understand the API description below. It seems that this attribute is read only? 


Link to comment
Share on other sites

The attribute is not read-only, but if you set it it will be used INSTEAD OF the 'rotation' attribute to compute the mesh rotation.

Wingnut is right, you don't reset the rotation of your physical body when resetting the player. In OIMO, there is a method called 'resetRotation'. 
Could you try this : 



Link to comment
Share on other sites

I wonder - what would happen if you reset the mesh's rotationQuaternion?


The Quaternion.Zero() function is rather misleading. A quaternion is "reset", when x,y,z are 0 but w is 1. For that you have the BABYLON.Quaternion.Identity() function.

Link to comment
Share on other sites

ahh, yup, I just "guessed-at" using Q.Zero().  Thanks R.  I think you might be right.

[lines removed here - further testing proved Wingnut's statements to be full-of-crap, so removed] :x


lines 88-98 area.  .rotation.y in render loop keeps on truckin, even after I set a 3-second-delayed quaternion.anything in line 92.

Why did I think that putting a rotationQuaternion onto tiledGround after 3 seconds... would stop the renderLoop rotater?  What was I thinking?

I tried setting the quaternion to Zero(), Identity(), copyFromFloats(0,0,0,1), it just wouldn't stop the .rotation.y.  hmm.  Go fig.  I have more learning to do.

Link to comment
Share on other sites

  • 2 weeks later...

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