Jump to content

Terrain Slope Problem?


Aerion
 Share

Recommended Posts

Hi folks! :) I've been working on putting together all the demos I've been working on in order to create a Player that can traverse a terrain correctly and will ONLY slide down the terrain if the Player detects a VERY steep slope ( X rotation should be able to be chosen by a parameter, the default set at 85 degrees on the X-Rotation axis ). I've created a play ground in order to demonstrate what I have done so far. I need some help to slide down steep terrain like in World of Warcraft. I'm VERY close but can't seem to figure out how to solve the above problem. Please be patient with me! :) I break easy! :P I have barely posted anything in the time I've come back to the forums after a 4-year hiatus. Also, yes there are visible rays that are attached to the player because I was trying to detect the steep x-rotation slope using raycasting. Without further adieu, here's the link to the playground : 

https://www.babylonjs-playground.com/#GDYDUL#2

Thank you all so VERY much for your help, kindness & patience! Once the playground is fixed I will leave it up for anyone else who needs this type of character / terrain controller! :)

Mythros

 

Link to comment
Share on other sites

We gave you the answer... nobody is going to script up or do the solution for you.. If your not willing to experiment and learn then perhaps.

BUTTTTT because I am a nice guy...

First off the error you are receiving is because the ground plane is being constructed in async, this is due to the fact that it has to download the heightmap before it can construct the mesh.  So the error you are receiving is due to the fact that its only a few milliseconds after the creation of the scene that its trying to update the facet data on a non-existent mesh.

so lets fix that first:
https://www.babylonjs-playground.com/#00KBR5#8
see line 196

Now I have some questions for you, why not use a physics system (don't get me wrong I love creating my own physics simulations from scratch but its not for everyone).  Second did you understand the math behind converting the normal vector into a "slide" vector, or does that need to be broken down as well?

Sorry if this came off as rude I'm kinda uncouth... 

Link to comment
Share on other sites

At the very least you should learn how to turn the difference of two positions into a direction vector.  You just subtract the vectors and then nomalize the result.  You can than use that vector to create your velocity by scaling it by a speed (number). 

You could use this knowledge to control the velocity up and down the slope.

 

 

Link to comment
Share on other sites

1 hour ago, Pryme8 said:

We gave you the answer... nobody is going to script up or do the solution for you.. If your not willing to experiment and learn then perhaps.

BUTTTTT because I am a nice guy...

First off the error you are receiving is because the ground plane is being constructed in async, this is due to the fact that it has to download the heightmap before it can construct the mesh.  So the error you are receiving is due to the fact that its only a few milliseconds after the creation of the scene that its trying to update the facet data on a non-existent mesh.

so lets fix that first:
https://www.babylonjs-playground.com/#00KBR5#8
see line 196

Now I have some questions for you, why not use a physics system (don't get me wrong I love creating my own physics simulations from scratch but its not for everyone).  Second did you understand the math behind converting the normal vector into a "slide" vector, or does that need to be broken down as well?

Sorry if this came off as rude I'm kinda uncouth... 

I've tried different physics system. I tried Oimo & I tried Cannon. None of them seems to have steep slope example. :( I would like to use Cannon for this if possible but Oimo is cool too. It is depressing no demos of steep slopes exists. As for second question, yes it needs to be broken down as wells.

Thank You <3

Mythros

 

Link to comment
Share on other sites

Physics-active players are not always easy to move/stop.

Mythros, have you TRIED moving a single box on a physics-active heightMap?

Mythros, I don't think anyone wants to be un-kind to you, but you are also asking for the moon and stars, somewhat impatiently, without putting in the coding hours and learning necessary to succeed in what you seek.  In other words, it appears to SOME of me... that you are looking for someone to write your game FOR you.

https://www.babylonjs-playground.com/#1RKZXB#79

See any "sliding down hills" happening there?  Yep... plenty.  Start small.  Use one box.  Can you program a navigation system for that physics-active box?  Something like making the W keypress do something similar-to box.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(0, 0, .01));

Do you understand?  Learn to "thrust" a physics-active box.  See if it slides down hills... the way you seek.  Later, that box can be made invisible, and a player model can be parented to it.

Another way to move a physics object... is using applyImpulse().  You can read about it anywhere, using forum and playground searches for that term.  Just for future info, "Anyone?" != reading/researching.  ;)  Are ya hearing me, my friend?  Gooood.

Experiment.  Build test demos for yourself... so you can study the sliding... and decide if you like it.  How much thrust/linearvelocity does it take to climb that hill?  How much acceleration happens when sliding down, per impostor mass and friction settings?  Only you... can determine which system is best.  It all starts... with seeing some physics sliding... as we see in the playground above.

You CAN simply force-set the .position of a physics-active mesh.  I already showed you a demo that aims the character with the mouse, and moves character with WASD.  So, insert THAT keypress system into THIS playground code.  According to our reclusive physics God Raanan, force-moving a mesh DOES ALSO move its invisible physics impostor.  SO, it should work.  But keep in mind... in physics land... it's also about CLIMBING hills, which takes more thrust/linearVelocity... just like in real life.

Experiment!  Be patient with yourself.  Am I being unkind?  I hope not.  Later, you may find this advice... quite valuable.

Link to comment
Share on other sites

Wingnut that actually was kind of rude. I do not wish be rude but I will not let anyone on forums ruin chance to see how @Pryme8's example works. And for reference, no I am not asking for the moon & stars. I find that offensive. I am asking for a simple example of how to slide down a STEEP slope with a controlled player Please be patient with me. I shatter very easily.

Thank You! <3

Mythros

 

Link to comment
Share on other sites

Nah, I would never try to keep you from seeing P8's example.  But you can do what I suggest, TOO, yes?

I'm only trying to help.  Tough love, ya know?   If you shatter from hearing truth, well then there's not much I can do about that, is there?  *shrug* 

More than once, I answered your queries when nobody else was doing so. 

I shatter easily too... when I speak opinionated truth, and then a reader "labels" that truth... as being rude.  Hopefully, later, you will realize the value of folks caring enough about you... to apply tough love.

Link to comment
Share on other sites

I'd just end up using cannon when I get around to doing it, so hit up a couple tutorials on the physics basics and proper techniques so the scene I put togeather you can understand.  It will probably be very simple and just demonstrate the principle. (Just like @Wingnut's prior example hint hint)

Link to comment
Share on other sites

If you use some BJS provided Ground object (or any inherited one), you can get directly the normals at any coordinates : http://doc.babylonjs.com/classes/3.0/groundmesh#getnormalatcoordinates-x-z-rarr-vector3-classes-3-0-vector3-

If you use any other mesh, you can activate the facetData feature that will built the facet normal array for you and give you a way to retrieve the nearest facet from some coordinates :  http://doc.babylonjs.com/tutorials/how_to_use_facetdata

example of a simple custom physics engine : https://www.babylonjs-playground.com/#7ATLX

Link to comment
Share on other sites

Hey, nice little spacebar-powered physics jumping ramp, P8.  Not sure WHY you would want to use facetData normals on a physics-active ground, but I'm game for anything.  :)

For those who want to do facet-Data testing WITHOUT physics engines (or with non-physics-engine physics), here's another playground... a minor mod of a PG handed to a user on a silver platter, earlier.

https://www.babylonjs-playground.com/#2CPTBX#21

It doesn't have collision, hill-climb or hill-slide, yet. 

It still has mouse-drag left-right for steering, plus I added some mouse-drag up/down for followCam height offset. 

This uses a testing terrain that Raggar created/sponsored, and the WASD keys are the player/box movers.

With steep hills like the above PG, first we have to detect collision with a "new face" (the side of a mountain)... then get the face normal, then... umm... what next?  Calculate a rise-angle based-upon the intersected face normal and direction of movement? 

Umm... if player is climbing the hill diagonally, that means we will need to be "sensing" new face collisions (multiple collisions) as we climb, and also knowing which move-direction... because the climb rate will be less steep if the player climbs the hill at an angle.

It gets math-ugly real quick, it seems.  My dog is whining, and that means trouble. 

What about sliding DOWN the hill at a diagonal angle?  Erf.  My brain hurts. With that case, sliding (with gravity acceleration) would affect both forward/backward AND sideways move-speed.

Does facet data normals give us the data needed to pull this off?   hmm.

Will there be times when our player/box is sitting-upon 3-10 faces all at the same time (including one of them being flat ground)?  Each face might have a slightly different face-normal angle.  Are we all going to get tumors from this?  :D 

Depending upon ground resolution/subdivs, the box could be sitting-upon (intersecting) 100 faces at the same time, each with different facetData normals.  Sum/average ALL, and then determine if box should be sliding down hill and how fast?  OMG!  I'm thinkin' that this task REQUIRES physics engine... if semi-realism is desired.  Two shoe models, left and right... with 2 Cannon meshImpostors on them.  Weeeee.

Can we farm-out this task to Russian hackers?  :D  Look at that, Myth.  P8 MADE the single-physics-active-mesh scene that I suggested YOU do.  Unreal.

Link to comment
Share on other sites

@Pryme8 This is awesome! :) Here my interpretation of how it work. I'm trying to keep the ball from floating up when rolling back down the hill and then holding the W or the Up key. Would like to get this working on terrain.

Also trying to get camera to always slowly rotate back to player no matter which way ball is rolling / rotating.

https://www.babylonjs-playground.com/#HFEP6C#6

Thank You! <3

Mythros

 

Link to comment
Share on other sites

28 minutes ago, Wingnut said:

Hey, nice little spacebar-powered physics jumping ramp, P8.  Not sure WHY you would want to use facetData normals on a physics-active ground, but I'm game for anything.  :)

Because Im a mad man ^_^, anyways Ill finish this up and it will make  a lot more since once I can get the facet data by location on the ribbon. (hint Im going to overwrite the inertia)

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.

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

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...