Jump to content

Checking the state of a physics enabled object


ruina
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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