Pryme8 Posted March 10, 2016 Share Posted March 10, 2016 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? Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 10, 2016 Share Posted March 10, 2016 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); Pryme8 1 Quote Link to comment Share on other sites More sharing options...
adam Posted March 10, 2016 Share Posted March 10, 2016 When using OIMO.js: You can check sphere.body.body.numContacts to see if it is in contact with another imposter. Use sphere.body.body.contactLink (linked list) to access the shapes it is in contact with. Use shape.parent to get the rigidbody. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 10, 2016 Author Share Posted March 10, 2016 Your awnsers combined solved all my questions concerning torque and grounded state thanks you friends! Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 11, 2016 Author Share Posted March 11, 2016 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 11, 2016 Author Share Posted March 11, 2016 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 :-( Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 17, 2016 Share Posted March 17, 2016 This line if from the physics impostor and not from the physics engine. Which would give a clue as to which object holds it playerObject.physicsImpostor.setAngularVelocity(vec3) would do the job. 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.