Jump to content

check if imposter is "grounded"


Pryme8
 Share

Recommended Posts

How would I go about only applying impulses to an imposter if it is in contact with another mesh that uses a mesh imposter?

 

scene.registerBeforeRender(function(){
		insideSphere.position = sphere.position;
		
		var forward = scene.activeCamera.position.subtract(sphere.position).normalize();
		forward.y = 0;
		
		if(keys.up){
			sphere.applyImpulse(forward.scale(-1), sphere.position);
		}else if(keys.down){
			sphere.applyImpulse(forward.scale(1), sphere.position);
			
		}
		
		if(keys.left){
			camera.spinAccel += 0.1;
			camera.rotationOffset -= camera.spinAccel;
			
			
		}else if(keys.right){
			camera.spinAccel += 0.1;
			camera.rotationOffset += camera.spinAccel;			
			
		}
		
		if(!keys.left && !keys.right){camera.spinAccel = 1}
			
	});

and then on a side note, is it possible to apply torque as apposed to an impulse?  I tried using:
 

var mq = sphere.rotationQuaternion;
		// create quaternion to add
		var q = BABYLON.Quaternion.RotationYawPitchRoll(0, -0.1, 0);
		sphere.rotationQuaternion = q.multiply(mq);
		sphere.body.body.setQuaternion(sphere.rotationQuaternion);
		sphere.body.body.sleeping = false;

but unfortunately that only spins the model and does not react to the physics engine it looks like?

Link to comment
Share on other sites

To your first question - you can only apply impulses to meshes that have physics impostors (of course you could simulate it by yourself, but then the physics engine is not iin the game at all). So you will have to create an impostor to this mesh and simply apply an impulse!

Or, did I misunderstand your question?

About your second question:

If you use Oimo.js you could apply angular velocity to the body, which will cause it to spin:

sphere.body.body.angularVelocity.init(velocity.x, velocity.y, velocity.z);

 

Link to comment
Share on other sites

ok, I dont mean to be a bother but...

How can I do the torque and the collide with cannon?  I need the meshImposter support...

***HALF SOLVED***
this is how I got around the grounded state

when I create the Imposter:

playerObj.MESH.body.grounded = false;
				
				playerObj.MESH.body.collisionResponse = 0;
				playerObj.MESH.body.addEventListener("collide", function(e){ playerObj.MESH.body.grounded = true;
				playerObj.MESH.body.collisionResponse = 1;
				 } );
				gameSettings.playerObject = playerObj.MESH;

on my scene register:
 

if(gameSettings.playerObject.body.collisionResponse){
			gameSettings.playerObject.body.grounded = true;
			}else{
			gameSettings.playerObject.body.grounded = false;	
			}
			if(keys.space && gameSettings.playerObject.body.grounded){
				gameSettings.playerObject.body.collisionResponse = 0;
				var jumpVector = new BABYLON.Vector3(0,6.5,0);
				gameSettings.playerObject.applyImpulse(jumpVector, gameSettings.playerObject.position);	
					
			}

there is a little extra script in there but anyone that wants check if an object is grounded can go about it in this manor.

Link to comment
Share on other sites

public setAngularVelocity(velocity: Vector3) {
            this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this, velocity);
        }

I have found this line in https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/babylon.physicsEngine.ts

but for some reason all attempts to call this method have failed
i figured it would be as simple as playerObject.setAngularVelocity(vec3) or playerObject.body.setAngularVelocity(vec3) or even playerObject.body.body.setAngularVelocity()  but all have failed :-(

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