Robin Posted October 25, 2017 Share Posted October 25, 2017 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 25, 2017 Share Posted October 25, 2017 Ping Ebook author @Temechon Quote Link to comment Share on other sites More sharing options...
Wingnut Posted October 26, 2017 Share Posted October 26, 2017 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. Quote Link to comment Share on other sites More sharing options...
Robin Posted October 26, 2017 Author Share Posted October 26, 2017 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? Quote Link to comment Share on other sites More sharing options...
Temechon Posted October 26, 2017 Share Posted October 26, 2017 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); Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 26, 2017 Share Posted October 26, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted October 26, 2017 Share Posted October 26, 2017 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. Quote Link to comment Share on other sites More sharing options...
Robin Posted November 7, 2017 Author Share Posted November 7, 2017 mesh.rotationQuaternion.copyFromFloats(0,0,0,1); Sorry for late reply, I just move house recently. The code above works for me! RaananW 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.