# solved Basic infinite scroller game

## Recommended Posts

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)?

##### Share on other sites

Hi @Tomm Huth, can you make a playground that repros the issue you are hitting?

##### Share on other sites

@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).

hi

how are you

##### Share on other sites
8 minutes ago, NasimiAsl said:

hi

how are you

what?

##### Share on other sites

i try find some auto generated sample  may be you can use that

##### Share on other sites

auto generating seems to work fine, but rather the physics stuff seems to be wonky.

##### Share on other sites

yes i have some sample for that too

##### Share on other sites

check out the playground i posted, it does recreate the problem.

##### Share on other sites

ok look this

http://www.babylonjs-playground.com/#1QC9DP#46 gravity + collision is enabled

##### Share on other sites

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

##### Share on other sites

for show you what happen you don't need terrain

i just have one  mesh and in any step prepare that again

##### Share on other sites

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.

##### Share on other sites

@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!

##### Share on other sites

Flagging as solved then