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 this post


Link to post
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). 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.