# Terrain Slope Problem?

## Recommended Posts

13 hours ago, Mythros said:

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);
this.avatar.moveWithCollisions(this.moveVector);
posy = this.avatar.position.y;
if ( posy > oldposy )
{
console.log ( 'YAY!' );
}```

wrong place to put the code. This code is executed when the av is falling down.

• Replies 63
• Created

#### Popular Days

20 hours ago, jerome said:

From the beginning of this post, I don't get why you don't use the BJS provided GroundMesh class what provides the ground altitude AND the ground normal at any coordinates (x, z) in the world ...

what do you do if the mesh is not moving on ground. In my demo how would you handle moving on the planks?

##### Share on other sites

@satguru Is there a way to after stopping sliding of the player when he is moving on the terrain & to increase the gravity and pull the user back down if they try to continue to climb / jump the slope?

Thank You!

Mythros

##### Share on other sites

I hope I explained good enough @satguru if not I can try to explain more in depth.

Thank You!

##### Share on other sites

@satguru did I explain well enough?

##### Share on other sites

Sorry I was away and also wasn't getting any notifications of your messages.

If instead of climbing up the slope and then sliding down when stationary, you want to prevent the player from climbing up the slope at all then yes that should be possible. Currently I check slope only when new y is less than old y but we can do that at other times too. Also instead of just one slope limit we can take two limits- min and max slope limits. If slope between min and max then  player can climb but will slide down if stationary , if more than max then player won't be able to climb at all. Will work on that when I have some time which probably won't be any time soon. Maybe an exercise for you ?

##### Share on other sites

O that's ok @satguru. Let me know when you have some spare time to work on it.

Thank You!

Mythros

##### Share on other sites

It would be awesome to see, that's for sure! <3

I'm so close...

##### Share on other sites

@satguru I've been trying for days to get this to work & it sorta' works but it still won't stop the player from advancing on steep slopes.

##### Share on other sites

Poor Mythros.  *sigh*  How are we going to set you on the path of righteousness?

You asked... "Why is there no demo that shows how to do this basic player movement with changing terrain slopes and sliding/blocking?"

There's no standard way of doing these calculations, and accelerated slidings.  You must code it... to make it act as you wish.  Console.log everything.  Learn how satguru's system works, and adapt it to work for you.  You seem to be against "hacking it out for yourself"... and I'm kindly asking WHY?

This terrain can be ANY rez/subdivs, so maybe the slope changes every 20 units walked, and maybe it changes every .1 units walked.  Needless to say, current slope needs to be calculated constantly... even while a slide or a blockage is happening.

Sliding?  Without using a physics engine/impostor, YOU must move the player yourself... to slide.  YOU must tell it to slide (unless you can convince someone to write your code FOR you).  Sliding is a movement of x, y, and z... all at the same time.  Y value must be constantly accelerated per the continuously-monitored slope-angle beneath the constantly-sliding player's feet.  WOW!

Blocking?  YOU must tell it to ignore movement commands in directions where angle > 30 degrees.

AND... you haven't even STARTED addressing momentum.  Myth... do you know what switchbacks, are?  Sure you do.  The slope COULD BE > 30 degrees, but if player uses diagonal switchback method, maybe they can still climb the hill.  It all depends upon whether/not you will allow "strafe" movement... side-stepping, and whether/not side-sliding is possible.  AND... are you going to use the same rules for side-sliding... as you are for forward/backward sliding/blocking?  I wouldn't, if I were you.  Humans can hold-place on steeper-angled hills... if they are standing sideways (using shoe/foot/ski edges).

And, can the player make the turn at the end of each switchback leg... without accidentally back-sliding down the hill?  There are no flat roads on our BJS terrain.  SO, when player makes a turn at the end of a switchback leg, he/she will have a "moment"-of... facing straight-up a > 30 deg angle, and the code says "slide backwards" if that happens, so the player is not able to make the switchback turn.

With me?  I hope so.  What you ask-for.... is very complicated.  There are TWO directions of movement that you must always "sum".  Sliding direction, and wanted movement direction.

CAN a player be walking forward JUST FINE (no sliding forward or backward happening)... yet be occasionally or continuously side-sliding?

If a player walks down a slope at a diagonal, could there be SOME sideways-sliding and SOME forward-sliding?

If a player slides down a LONG slope, will you want to add acceleration?  If the slope suddenly changes from > 30 degs.... to 28 degrees... will the player's mass, friction, momentum (inertia)... make him/her slide MORE... even on the 28 degree terrain?  He/She will have quite a bit of speed.

What if a logging truck accidentally fell-off one of those switchback roads?  Do you think the truck would stop when it landed on the switchback road below?  Unlikely.  It's speed/momentum would likely make it go all the way to the bottom, ignoring ALL < 30 degree terrain on the way.  You have SO MANY THINGS to take into consideration... for this project.  Using physics engine/impostor... would handle MOST of your hassles.  But... "walking" a physics impostor... is known to be a challenge, too.  IT will ALSO cause you to do special and deep coding.

This is a sufficiently complicated project... that you MIGHT want to avoid "hounding" anyone, about it. Not saying that you have done that, but, you know, tact and all.

So again, why don't you want to simply "grind out the solution"?  Don't you LOVE programming and console.logging other people's code/variables, and watch the numbers, and learn how things are done, so you can borrow those techniques for other projects?  How can you NOT love doing that?  It's wonderful, and it has a self-satisfaction quotient the size of the moon.    Ya got a powerful robotics system in JS, ya got a geometry playground that listens to JS... just tell it what ya want it to do.  It takes orders GREAT.

Was I kind, in this post?  I hope I didn't hurt your feelings.

##### Share on other sites

12 hours ago, Mythros said:

@satguru I've been trying for days to get this to work & it sorta' works but it still won't stop the player from advancing on steep slopes.

Are you able to detect the slope of the terrain?  If not, work on that.

##### Share on other sites

Or just detect the change in y of the player and adjust speed however you would like according to that.

edit:  by "change in y" I mean what the y position would be changing to without this feature.

##### Share on other sites

Are you able to detect the slope of the terrain?  If not, work on that

Yep, yep, and yep.    Ideally, both angle and direction of the slope, near-continuously monitored while player is moving around.  Place an arrow thru the player, and make it point up/down the current slope angle/direction.  Make the arrow change colors when angle > 30 degrees.  Coooooool.  Great little test bed.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.