ruina Posted August 26, 2016 Share Posted August 26, 2016 With physics enabled, If a box is thrown into the scene, which could be the best way of checking if the box has already stopped? I'm now checking in regular intervals whether the previous position of the box minus the current position is below certain threshold. It is working, but not sure if that is the better way of doing that. Also, is there a simple way to know which face of the box is facing the ground in one particular moment? I guess that comparing the current rotation property with the starting one, but again, not sure if this is how it should be done. Quote Link to comment Share on other sites More sharing options...
Cybercell Posted August 26, 2016 Share Posted August 26, 2016 Derp nvm did not figure it out. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 26, 2016 Share Posted August 26, 2016 player_box.body.grounded = false; player_box.body.collisionResponse = 0; player_box.body.addEventListener("collide", function(e){ player_box.body.grounded = true; player_box.body.collisionResponse = 1; }); scene.registerBeforeRender(function(){ //console.log(player_box.position); if(player_box.body.collisionResponse){ player_box.body.grounded = true; player_box.body.velocity.y = 0; }else{ player_box.body.grounded = false; } } Create a listener for a collision event and do what you need accordingly. The "face" that is facing down will always be the cross product of the global up and the local up of the mesh I believe (thats off the top of my head I might be wrong). But you would need to do a vector comparison of a constant up vector and what ever the meshs local rotation vector is to get a local rotation, from there you could establish whats the closest face to the ground even if the mesh is rotated a bunch of different ways. I think there is even a function that returns local to global coordinates in the form of a matrix that has a normalized rotation vector in it. <<< umm who knows that, one second... ooo I know Summoning : @adam Im gonna be honest with all the things that are simple to me Matrix's blow my mind... I think I need to do a week long study on them. Quote Link to comment Share on other sites More sharing options...
adam Posted August 26, 2016 Share Posted August 26, 2016 This thread should be helpful: 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.