PhantomWarrior562 Posted June 12, 2018 Share Posted June 12, 2018 Language: TypeScript Physics Engine: CannonJS Hey all, I would appreciate it if someone would help me solve these 2 mesh physics problems that I feel are related. I spent a lot of time trying to solve these related issues on my own and could not figure out what was going wrong. RELEVANT NOTE: BOTH problems occur right after switching from 1 scene to another scene. They only happen right after a scene loads. I have a video that demonstrates the error below. Problem 1: After loading each mesh (each with its own physics impostor), each mesh jumps a little (and then afterwards, they start falling because of gravity). I was wondering why/how to prevent it from happening. Note: I suspected that it is because they load too close to the ground and bounce because the computer erroneously thinks that the meshes/ground are touching. I am able to lessen the jump by making the ground’s position.y = -0.5 (so it is even clearer to the computer that the objects are not touching because all objects right now load at position.y = 0 (and I move objects before the next object loads so they don't intersect and start a collision)), but the jump still occurs, just less of a jump and still noticeable. Problem 2: After loading a certain scene, after being loaded, each instance of a special object I created (a class I created that includes a mesh) jumps in opposite directions from each other. I’m not sure why. I have a feeling it has to do with having multiple instances of the same class, each with their own mesh. After the scene loads, I am able to individually access each mesh and have them move individually, so their movement isn’t intertwined. Code/Video in Link: Relevant code and 1 video demonstrating error are in the Dropbox link. Note: The video shows both errors happening at the same time. Note: The code in this folder are not in the same directory/folder structure that I normally use for this program (so that is not the cause of my issues) [Link Removed] Thank you to all who read/and might help me with this issue! Quote Link to comment Share on other sites More sharing options...
Guest Posted June 12, 2018 Share Posted June 12, 2018 Hello!! it could be far easier for us to help if you could provide a repro in the Playground Quote Link to comment Share on other sites More sharing options...
PhantomWarrior562 Posted June 13, 2018 Author Share Posted June 13, 2018 Hi Deltakosh! Thanks for responding! I'm having trouble translating my project for the playground. How do I translate the following code into something that the playground can read? I use the following code to delete the current scene and load a new one. this._scene.dispose(); this._scene = null; //Is this line needed to make .dispose() work so the garbage collection automatically clears the previous scene? this.createScene(); (Different if statements in the createScene creates different scenes.) Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Guest Posted June 13, 2018 Share Posted June 13, 2018 You can control the renderloop like in this sample: https://www.babylonjs-playground.com/#1LQGCI#1 PhantomWarrior562 1 Quote Link to comment Share on other sites More sharing options...
PhantomWarrior562 Posted June 14, 2018 Author Share Posted June 14, 2018 Thank you! I'll update the post as soon as I put my code onto the playground. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
PhantomWarrior562 Posted August 2, 2018 Author Share Posted August 2, 2018 Hey @Deltakosh and whoever else who might be reading these, I’m so sorry for the late response. I fixed my issue while I was bringing my code onto the playground and then forgot about responding here. Hopefully the following can help if anyone else runs into this programming issue in the future. In Summary: Always use theMesh.setPosition before creating theMesh’s physicsImpostor. Otherwise, the following occurs: -Each mesh’s physicsImpostor remains at the origin (where each mesh is originally created) and the program doesn’t move the physicsImpostor to the mesh’s actual location for a brief millisecond (unnoticeable by the human eye). Thus, for a brief second during creation, all meshes’ physicsImpostors bounce off of one another. Even though after that millisecond when the program teleports each physicsImpostor to their corresponding meshes’ locations, the physicsImpostors’ accelerations from that each bounce is kept. Thus, to the human eye, it looks like each mesh is bouncing off of nothing. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 2, 2018 Share Posted August 2, 2018 On 8/2/2018 at 2:58 PM, PhantomWarrior562 said: In Summary: Always use theMesh.setPosition before creating theMesh’s physicsImpostor. I dont know how 100% that is... I have created a myriad of simulations using bjs and have never ran into that problem. Are you sure its not a timing issue? Seems pretty specific, Id have to see your video. *UPDATE* I have run into a simulation that has this problem now, so I will bite my tongue. @PhantomWarrior562 any ideas for an Oimo solution? Quote Link to comment Share on other sites More sharing options...
PhantomWarrior562 Posted March 18, 2019 Author Share Posted March 18, 2019 Hi Pryme8, I didn't see your reply and wow, it has been a long time. I apologize for not responding, and I hope you found a solution! Off the top of my head, I am not sure how to solve this issue. 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.