Jump to content

[Solved] Switching/Loading Scene Causes Mesh Jumping

Recommended Posts

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!


Link to comment
Share on other sites

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 = null; //Is this line needed to make .dispose() work so the garbage collection automatically clears the previous scene?

(Different if statements in the createScene creates different scenes.)

Thanks for the help!




Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

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.


I have run into a simulation that has this problem now, so I will bite my tongue. @PhantomWarrior562 any ideas for an Oimo solution?

Link to comment
Share on other sites

  • 7 months later...

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.

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.


  • Recently Browsing   0 members

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