Sign in to follow this  
Robin

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.impostor.setLinearVelocity(BABYLON.Vector3.Zero());
     this.impostor.setAngularVelocity(BABYLON.Vector3.Zero());
     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.

  

blob.thumb.png.3564adb54df8a7bfca30be09952523cd.png

Share this post


Link to post
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.

Share this post


Link to post
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? 

image.thumb.png.5f88ab9cac84fd56f0b6913c357fb585.png

Share this post


Link to post
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 : 

this.body.resetRotation(0,0,0);

 

Share this post


Link to post
Share on other sites

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

mesh.rotationQuaternion.copyFromFloats(0,0,0,1);

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.

Share this post


Link to post
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

https://www.babylonjs-playground.com/#1FXAOY#5

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.