Jump to content

Terrain Slope Problem?


Recommended Posts


See if this helps.

This just uses moveWithCollisions and some simple physics.


You will see three planks at different angles.

The first plank is less than 30 degree, the other two more than 30 degree.

Use WASD or arrow keys to walk the AV over each of those planks.

The AV slides down the more than 30 degree planks if its stops while walking up those planks.

The slide slope limit is set to 30 degree.

The code


The slide slope limit is set here



Link to comment
Share on other sites

Yes, that helps. Infact, it is PERFECT! But do you have an easier example embedding the exact camera in this demo with the camera collisions, and the slope sliding functions? No offense meant at all by this but this source code is way too convoluted.

Thank You!



Link to comment
Share on other sites


The code is a bit convoluted because it is still work in progress. This was inline my main Vishva code. I separated it out into its own class to make it reusable. It is still not complete and I am not sure when I will be able to complete it. 
When I get some time I will put together  a simple playground example to show how it can be used in its current state.

The idea  behind it is actually very simple.
In each frame, based on walk speed, gravity etc., I decide by how much amount do I want to move the mesh in x, y and z direction.
I then use moveWithCollision to move it by that amount.
I then check to see  by how much amount did  it actually move. This provides some hint on what might be  happening. I then take some action based on that.

So lets say I want to move the mesh by -2 meter in y direction but if after moveWithCollision I see that it hasn't moved at all in that direction  I then conclude  that the mesh might be on ground 
But  if I see that it  did, actually, move by -2 meter, I then conclude it is in free fall and I start accelerating it down further
For slope I compare the old and new position to calculate the slope by which the mesh moved in vertical plane. If the slope is less than the slope limit I move the mesh back to its old position else I let it slide down.

Link to comment
Share on other sites

Thank you bro! This is awesome! :) I have 3 questions. How can you detect if the player is climbing up the hill? What's up with the Camera? Why is it not colliding with the ground & I can't rotate it with the mouse buttons? A combination of the ArcRotateCamera & Follow Camera would be AMAZING!

Here's my rendition : 


Thanks so much! <3



Link to comment
Share on other sites

7 hours ago, Mythros said:

Here's my rendition : 

In your PG you have a lot of unecessary code, all the canvas and engine bits are dealt with by the PG. Check out Satguru's structure for his PG. Also read this http://babylonjsguide.github.io/begins/Introducing_Babylonjs

It will help make your PGs more readable for those who want to help.

Link to comment
Share on other sites


Regarding "How can you detect if the player is climbing up the hill?".

Compare the Y position of mesh before  and after MoveWithCollision. If it has increased then it means the mesh is being probably pushed up a slope.

Regarding FollowCamera.

ArcRotateCamera worked well for most of my use cases so I never looked into using FollowCamera. So  I do not have much knowledge about that. I will eventually look into  it but for now, unfortunately,  you are on your own as regards that :(


Link to comment
Share on other sites

@satguru why does the player not continue to gain gravity as he's falling when holding the left / right or A / D keys in the air? The player just sorta' floats down after the jump and holding the A / D or left / right keys. Why when on the terrain as you travel up steeper parts of the terrain the gravity does not slowly increase until the player reaches a slightly less steep incline?


Thank you! <3



Link to comment
Share on other sites

Because @satguru's demo is what I'm looking for.

@satguru I tried to figure out checking if the player is climbing up the slope & can't seem to figure it out. Here's my rendition : 


Lines 298 - 312

oldposy = this.avatar.position.y;
	                    this.moveVector.copyFromFloats(0, -this.downDist, 0);
	                    posy = this.avatar.position.y;
	                    if ( posy > oldposy )
	                        console.log ( 'YAY!' );


Link to comment
Share on other sites

On 8/13/2017 at 6:53 AM, Mythros said:

@satguru I forgot the terrain has to be bigger in order to see this problem. So I made another rendition.


Do not see the sphere falling down in air. Do not see the problem. If you check my demo you can see the AV accelerate down when it walks off the planks

Link to comment
Share on other sites

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