Search the Community

Showing results for tags 'cannonjs'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 14 results

  1. karylo

    CannonJS elastic collisions

    A newbie with CannonJS, I want to have spheres collide with elasticity such that there is no loss of kinetic energy. All the spheres have the same physicsMaterial and the ContactMaterial has friction = 0.0 and restitution = 1.0. I was hoping that would give me 100% elastic collisions yet I see that the spheres lose significant energy with every collision. Is there something else I could or should be doing? TIA // Create a slippery material (friction coefficient = 0.0) // and very bouncy (restitution coefficient = 1.0) var physicsMaterial = new CANNON.Material("bouncyMaterial"); var physicsContactMaterial = new CANNON.ContactMaterial(physicsMaterial, physicsMaterial, 0.0, // friction coefficient 1.0 // restitution ); // We must add the contact materials to the world world.addContactMaterial(physicsContactMaterial); // CANNON body this.body = new CANNON.Body({ mass: this.mass, position: this.loc, shape: new CANNON.Sphere(this.radius), velocity: this.vel, linearDamping: 0, material: physicsMaterial });
  2. Hey all! I’m a beginner at BabylonJS and ran into a problem. I spent a long time researching how to solve this on the internet, and couldn’t find a solution. I am running a HTML/JavaScript file locally with BabylonJS and my BabylonJS file is unable to see that I am (using a Cannon.js CDN)/(have Cannon.js saved locally) and prints the following error in the console window: BJS - CannonJS is not available. Please make sure you included the js file. BJS - [17:17:19]: Physics Engine CannonJSPlugin cannot be found. Please make sure it is included. This printout happens when I call “scene.enablePhysics();”. My project works just fine otherwise. (More errors appear when I try to use the physics engine that didn’t load, but that isn’t applicable here.) When I don’t enable physics, this error does not occur but of course, the physics engine doesn’t work then. I am using the following for CDN-calling: <script src="https://cdn.babylonjs.com/cannon.js"> When that didn’t work, I tried using the following below after having downloaded a copy of cannon.js (and putting it in the same folder as the .html file that is using BabylonJS). <script src="cannon.js"></script> I feel like I’m missing something very simple, but I’m not sure what it is. Something similar is happening when I try to use Oimo.js (though I would prefer cannon.js). I get the following error for Oimo.js ( “scene.enablePhysics(new BABYLON.Vector3(0,-9.81, 0), new BABYLON.OimoJSPlugin());”): babylon.js:44 Uncaught TypeError: Cannot read property 'World' of undefined at new i (babylon.js:44) at createScene (PlayingAround.html:193) at PlayingAround.html:330 Putting this code in a playground does not make sense because this line of code “scene.enablePhysics();” works just fine in the playground. I was wondering how I could fix this issue. Thanks in advance for the help!
  3. <!DOCTYPE html> <html> <head> <script src='./node_modules/babylonjs/dist/preview release/babylon.js'></script> <script src='./node_modules/babylonjs/dist/preview release/cannon.js'></script> <script> document.addEventListener('DOMContentLoaded', () => { const canvas = document.getElementById('renderCanvas') const engine = new BABYLON.Engine(canvas) const scene = new BABYLON.Scene(engine) scene.enablePhysics() const physicsHelper = new BABYLON.PhysicsHelper(scene) const camera = new BABYLON.ArcRotateCamera('camera', 1, 20, 10, new BABYLON.Vector3(20, 0, 0)) camera.setPosition(new BABYLON.Vector3(0, 20, -30)) scene.activeCamera.attachControl(canvas) const sun = new BABYLON.HemisphericLight('', new BABYLON.Vector3(0, 1, 0)) sun.diffuse = new BABYLON.Color3(0.8, 0.8, 0.8) sun.groundColor = new BABYLON.Color3(0.1, 0.1, 0.1) const box = BABYLON.MeshBuilder.CreateBox('active', { size: 0.9 }) const boxMaterial = new BABYLON.StandardMaterial('') boxMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 1) box.material = boxMaterial box.physicsImposter = new BABYLON.PhysicsImpostor(box, BABYLON.PhysicsImpostor.BoxImposter, { mass: 1, restitution: 0.9, friction: 1 }) }) </script> </head> <body> <canvas id='renderCanvas'></canvas> </body> </html> Any ideas why this code gives the following error? cannon.js:5756 Uncaught TypeError: Cannot read property 'calculateWorldAABB' of undefined at Body.computeAABB (cannon.js:5756) at Body.updateMassProperties (cannon.js:5930) at Body.addShape (cannon.js:5693) at t.generatePhysicsBody (babylon.js:43) at t.addImpostor (babylon.js:43) at t._init (babylon.js:43) at new t (babylon.js:43) at HTMLDocument.document.addEventListener ((index):32) I'm using the latest GitHub code `Babylon.js engine (v3.2.0-alphaC) launched`
  4. Hello again people! Well, I have a little problem with collisions in babylon with cannon js. For example: I move my player with translate, it's just a box with box impostor, and when I go and crash with another box the player is throw in the other sense, here it's all ok but the force with the player is throw it's very strong. I tried with resitution = 0 or friction = 1 but happens the same strong counter force. So, can anyone help me?
  5. So.... to my great disappointment - yes, another one of those - it looks like parented meshes don't work with physics engine. Is there any workaround? I think it's impossible for me to unroll all parenting in the project, it would break animations and god knows what else... BTW it looks like @Wingnut is currently working on similar issues (poor physics support). thumbs up to you for all the great work
  6. Hi guys, coming soon to the babylon.js near you - height maps using cannon.js! The image attached shows a prototype of the heightmap integration. There are a few problems to be solved, but 2.3 will have an impostor for heightmap (for now for cannon.js only).
  7. I am using CannonJS with BabylonJS, and I want to make a stack of 3 boxes, all the same size, but when I do, they slowly slide around until the stack topples. I have tried setting restitution to 0, and various values for gravity, mass, and friction, and regardless, the stack always topples itself undesirably. I only want them to topple when rammed with some other object. How can I achieve this?
  8. I am new to 3D game dev, and I'm wondering how to make a triangular prism that a sphere could roll down. I think I'm missing something huge, because physics libraries only seem to support the most basic geometries, excluding triangular prisms and other important shapes. Could someone please point me to some resources or explain how to deal with physical interactions between more complicated shapes? I notice that BabylonJS makes it easy to create lots of neat meshes, however, I'm missing how to simulate their shapes on the CannonJS side of things. I want to make a game where the player controls a sphere by rolling it around various scenes, but it just doesn't seem possible using only spheres and boxes, for example.
  9. How to dispose a material on run time and dynamically create again. I want when my sphere material collide with floor material my sphere material should dispose completely and I want to create a new sphere material again. @Deltakosh @Wingnut @Dad72
  10. Hi again, it's going to be long and maybe silly post once again. Today's topic is character animation and movement using physics (Cannon.js for now). Still doing the Bomberman clone. I've been digging for a some kind of a tutorial for this, but have not found it so far. What I basically wish to know is how to: Import a character with animations "the right way". I currently have a character, which has animations for idle/walking/running/jumping(start/looping/end). The problem is, the animations are all in different files and the format is FBX. So, what is the preferred way to import my character to BabylonJS? Should I just try to mash all the animations in a single file somehow? Currently, if I export the FBX to .babylon format, I get multiple files for each animation. When I import the animations to my scene, they are all playing by default. Sorry if this is a beginner question... Move a character using physics properly. I guess the main idea is similar to what Unity does. I created a picture (Image 1) attached to my post to demonstrate what I mean. I currently have a SphereImpostor, which is moving using keyboard controls (using addImpulse). Now, I guess what I need to do is kind of have all the other stuff such as the visible mesh that has the animations and the box for wall collisions to somehow stick with the ball that is moving. And also to rotate the animation to the direction where the ball is leading the character Am I on the right track here? Image 1: How I would like the 'character' to be like. Some threads that I dug up on the similar matters: Buuuut he decided to not use physics at all. Also found this demo, but it's from 2014... http://babylonplayground.azurewebsites.net/babyoncharacterwalk
  11. Hi, just a short question about physics usage. I use Cannon.js for now, moving to Oimo.js later on. Anyways, I'm making a Bomberman clone with physics turned on. Let's say that I have a 20 x 20 grid. Bomb explodes in my game and this should destroy some random tile. After I dispose the mesh, the physics impostor seems to be there still, since my trusty old debug ball happily rolls over the empty space. The question is: How to remove mesh and its physics properties from the scene?
  12. I have am running a 3D multiplayer physics game where I currently send the input (4 keys, position: x,y,z and velocity x,y) to the clients (8 clients in total) 30 times a second. Is this considered to be a bit too much? Also, I assume changing (1) to (2) would decrease the size of data that is sent? (1) var keys = {l:true, r:true, u:true, d:true}; (2) var keys = {l:1, r:t1, u:1, d:1};
  13. Threedy

    Cannonjs: sphere doesn't fall down

    Edit: Problem fixed. After some experimenting, I realized that the gravity should be passed like this: world.gravity = vector. Hi, I have the following simple example from the wiki page of Cannon JS... I expected the ball to fall, but it didn't and only prints ''Sphere position: 0,100,10''. Can anyone understand why? I then thought (based from the wiki) that I had to use Rigidbody (CANNON.RigidBody) but that wasn't recognized. Any tip is greatly appreciated.
  14. I'm using ThreeJS and I've created a basic scene in which I've imported some objects from a dae file. Everything is going great except when I try to apply a basic box body to an imported mesh with CannonJS. If I create a cube with code and apply Physics to it, it works fine. But, if I try and added Physics to an imported model it seems that the bound box shape for the Physics is to big (I'm guessing that's what it happening). Here is the scene: http://filmsbykris.com/tmp/cannonjs/ You will see that the smaller boxes and the large ground box, seem to work just fine. But, the larger box seems to be floating. I've set it to flip every 2 seconds just so you can see how it's moving. The function I've put together this function to apply the physics. (I'm guessing that this is where the problem is) function addBoxPhy(obj){ var mesh = obj.children[0]; if(mesh.type == "Mesh"){ var halfExtents = new CANNON.Vec3(.5,.5,.5); var boxShape = new CANNON.Box(halfExtents); var boxBody = new CANNON.Body({ mass: 5 }); boxBody.addShape(boxShape); world.add(boxBody); boxBody.position.copy(mesh.position); boxMeshes.push(mesh); boxes.push(boxBody); daeBox = boxBody; } }I've been trying to figure this out for a day or two now. Any help would be great. Thanks