Tomm Huth Posted October 11, 2018 Share Posted October 11, 2018 I'm playing around with an infinite scroller game idea (think Temple Run) on the basis that the player stands still, and the terrain moves towards the camera, giving the illusion of forward motion. I added some simple random box meshes on top of the path that the user needs to navigate around (game over otherwise), and some gaps in the ground that the player can fall thru (game over). Since i need collision detection and basic player gravity I set up using CannonJS. That seems to work OK: the player would fall through the gaps, but for some reason the hit detection for the obstacles would bug out, sometimes letting the player mesh go halfway thru (imposter out of sync with mesh). For the motion of the path blocks i simply did mesh.position.z -= .1 in each render loop. After reading some more on this it seems like manipulating physics objects like this is not a good idea (should use impulse/force instead)? Funny thing is, if I turned down the speed to a crawl the imposter worked as it should and seemed to match up with the mesh. If I can't use this approach to moving the ground, what would be a better solution? I also thought about setting a linear velocity in the ground, but since its mass is set to 0 this has no effect. I think my main question is this: How can I implement a simple gravity + jump functionality manually (colliding with a flat predicable/same height ground)? Quote Link to comment Share on other sites More sharing options...
kcoley Posted October 12, 2018 Share Posted October 12, 2018 Hi @Tomm Huth, can you make a playground that repros the issue you are hitting? Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 14, 2018 Author Share Posted October 14, 2018 @kcoley I've played around with this some more and decided on another approach: the player moves and the world is still, with physics back. seems to work good except for some occational jerky motion of the moving player (just a simple sphere). The player (sphere) has a linearVelocity set to z = 4. You can also see this in this super basic playground: http://www.babylonjs-playground.com/indexStable.html#VU94KB#1 Be patient tho. it does not appear immediately, but you should notice the sphere quicky skipping back and forth eventually. Try restarting the playground or let it run in the background. Has it got something to do with linearVelocity being set? angularVelocity seems to produce the same (and feels generally much more unpredictable and does not really create the permanent forward motion I'm looking for). Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 14, 2018 Share Posted October 14, 2018 hi how are you http://www.babylonjs-playground.com/#1QC9DP#143 ssaket and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 14, 2018 Author Share Posted October 14, 2018 8 minutes ago, NasimiAsl said: hi how are you http://www.babylonjs-playground.com/#1QC9DP#143 what? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 14, 2018 Share Posted October 14, 2018 i try find some auto generated sample may be you can use that https://playground.babylonjs.com/#1V70NA#20 Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 14, 2018 Author Share Posted October 14, 2018 auto generating seems to work fine, but rather the physics stuff seems to be wonky. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 14, 2018 Share Posted October 14, 2018 yes i have some sample for that too Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 14, 2018 Author Share Posted October 14, 2018 check out the playground i posted, it does recreate the problem. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 14, 2018 Share Posted October 14, 2018 ok look this http://www.babylonjs-playground.com/#1QC9DP#46 gravity + collision is enabled Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 14, 2018 Author Share Posted October 14, 2018 i'm not really looking for terrain here, and am happy with simple boxes, but thanks the real issue here is figuring out why the sphere skips around Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted October 14, 2018 Share Posted October 14, 2018 for show you what happen you don't need terrain i just have one mesh and in any step prepare that again http://www.babylonjs-playground.com/#1QC9DP#175 JackFalcon and ssaket 2 Quote Link to comment Share on other sites More sharing options...
kcoley Posted October 15, 2018 Share Posted October 15, 2018 Hi @Tomm Huth , this seems to be related to cannon.js and collisions since it's physics related. You can probably post an issue on their GitHub page (https://github.com/schteppe/cannon.js) explaining what you are trying to do and someone there may be able to help with the parameters. Quote Link to comment Share on other sites More sharing options...
Tomm Huth Posted October 15, 2018 Author Share Posted October 15, 2018 @kcoley i actually managed to fix it by tweaking the iterations param of the cannonjs plugin, but it would be interesting to know why that seemingly solved it. thanks! GameMonetize and kcoley 2 Quote Link to comment Share on other sites More sharing options...
Guest Posted October 15, 2018 Share Posted October 15, 2018 Flagging as solved then 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.