Jump to content

moveWithCollisions-a lot of questions


moxierichard
 Share

Recommended Posts

Hi,

I saw the code presented  in the link  https://playground.babylonjs.com/#1NQTNE#11  and played many times.

I felt "moveWithCollisions" is full of magic .

it seems that with the help of "movewithCollisions" the mesh can smartly move and move little by little and finally manage to find its path to reach its destination. 

I checked the code but was not able to figure out how to use it exactly,  there is few comment or remarks to tell what's the purpose of  some important lines .

so I listed these important lines that I didn't understand as below.

can anyone please help to explain what's the purpose of these critical  lines?  (please notice that I use "//" to bring up what my question is )

// move to clicked coordinates
       ............
        if(meshPlayer.destination) {
            var moveVector = meshPlayer.destination.subtract(meshPlayer.position);
 
            if (moveVector.length() > 1.1) {  //1.why use 1.1 ,other than 2.2 or 0.8 or any length else? is it related to the player size 1 while downcasting a ray    ?         
                moveVector.y = GRAVITY;     //2.GRAVITY is -0.5 as defined earlier, but why moveVector.y  must be  -0.5? what's the purpose to assign moveVector.y ?
                moveVector = moveVector.normalize();//3.what's the purpose of "normalize"?what's the benefit of doing this? is this line mandatory? 
                moveVector = moveVector.scale(0.2);  //4.why to shrink the moveVector to 1/5 of its original size? why not 0.1 or 2 or some number else? 
                if(meshFound.distance > 1.1){moveVector.y = GRAVITY;}    //5.why 1.1 again? 
                meshPlayer.moveWithCollisions(moveVector);
            } else {
                
               meshPlayer.destination = null;
                }
        }
..........
 
It's really appreciated for your time.
 

Your content will need to be approved by a moderator
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...