Jump to content

Chess / Tailed Map


Recommended Posts

Hi, i wonder how could i do something like 3d chess.

1) So lets say, there should be a tailed 3d map (i already saw tutorials to do it ;)).

2) Lets say in one tail there is a cube(or any mesh). Here i dont know how to set right position to the center of certain tail.

3) And than i would like to know how can i drag the cube to another tail, but at the same time i should check that the drag is inside the limited field.

Any suggestions, links for some useful tutorials or pieces of code?

Link to comment
Share on other sites

Hi EvilMax, welcome to the forum!  Yes, all your dreams can come true... with Babylon.js.  And you don't necessarily need to use a tiled ground.  You can create the "tiled" effect.... by using a texture.


A pretty good start, eh?  Drag on background color... to pan cam. 

That web site is called "The Playground".  We BJS folk edit, test, experiment, run, save, zip... and have tons of fun, there.  It is a great way to share small webGL scenes with one another, and help each other find solutions.

Although your playground demo now has a decent tiled board, and has drag'n'drop working well (with help from our drag-and-drop pre-made playground demo)... you still need "snap", right?  When the user has dragged a mesh more than 50% across a tile border, you would like to "snap" the mesh to tile center... in onPointerUp, yes?  You don't want any mesh "sitting on the fence" sotospeak, right?

So, you have more fun ahead.  You might want to think about HOW BIG is that ground/board that is created in line 16.  300 by 300.  Hmm.  Looks like EvilMax will be writing a function.... perhaps called "snapAll()".  Perhaps it "squares-up" all mesh on the board.  Or possibly... it ONLY squares-up the most-recently MOVED mesh.  There is adventure ahead for EvilMax and his forum of super-helpers.

Again, welcome to the forum, welcome to Babylon.js, and just plain welcome.  Try out some "snap" experiments... a little math... a little web reading... a little bravery.  You can edit, run, and save as much as you like... in the playground.  It is impossible to over-write anything or do anything bad.  In fact, some of us think it is great fun to see how well we can blow-up the playground and its edited scene.  :)  Remember, when editing in the playground, hit RUN over and over, but avoid control-r (reload)... which could cause you heartache.  (there is a warning alert - so don't worry)  Have fun, stay in touch.

Link to comment
Share on other sites

Hi again EM.  Sure, ray would work fine.  But, hmm, keep in mind that you COULD maintain a 2 dimensional array in JS, and therefore you would KNOW which array elements of the board were occupied, and which not, well before the user tried to move.  If your internal JS array tester says there is a mesh already in that array slot, then the move will be refused.  They might be disallowed from even TRYING to do that drag-attempt.

Also, your mesh won't be "normal" mesh.  They will each have special behaviors.  For example, user "picks-up" a position.  Your JS quickly queries your array and discovers that the user has chosen a position with a chess piece on it... because there is an [object] in your boardTileArray at that location.  That object could be or is... a mesh.  But then you discover that it is a knight.  Knights have move-distance/location limitations.  The knight object itself (a standard mesh but it could have added knight-methods and knight-properties)... could be smart.  IT could "carry" its knight-characteristics.  IT... could check if the user is trying a "legal" move for knight-class mesh.

This is one possible design strategy.  Quickly hand-off the "check if this move is ok"-task... to the chess piece that is trying to be moved.  Maybe let IT allow or refuse the move.  This would require creating a new subclass from Babylon.Mesh, I suppose.  Perhaps a mesh.chesspiece class, and then mesh.chesspiece.knight class, etc.  A different class for each TYPE of chess piece.   Perhaps... baseobj.chesspiece.knight.toMesh().  Know anything about OOP?  I don't.

:)  I'm really not a good game designer.  I hope smarter people than I... leave comments, too.  My ideas are not always good ideas.  heh

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