Jump to content

Mesh to follow a path/curve


Recommended Posts

So I wrote this little script that has a Cube move from one empty to another to make it's way through a maze to another Cube.



My question is, Can a get an object to follow a path/curve?

I've tried Googling "babylonjs follow path", but didn't find anything.

Is this possible at this point?
Am I using the wrong wording in my searching?


Thanks for any help.

Link to comment
Share on other sites

Hi Metal. I'm kind of a newbie on this, but has far has i know, there isn't, anyway.... It's quite easy to implement. I'll pass you the code I implemented in opengl 2 years ago, you just have to adapt to javascript. :)

//varáveis da curva de besierGLfloat ctrlpoints[4][3] = {	{ 12000.0, 0.0, 0.0}, { 17000.0, 0.0, -12800.0}, 	{-9000.0, 0.0, 0.0}, {12000.0, 0.0, 0.0}};GLfloat besx,besy,besz;float tempo = 0.0f;//Calculo de cruva de beziervoid calculatePoly(float t){		 int i=1;		 float a = -t*t*t + 3*t*t - 3*t + 1;		 float b = 3*t*t*t + -6*t*t + 3*t;		 float c = -3*t*t*t + 3*t*t;		 float d = t*t*t;		 besx = (ctrlpoints[i-1][0]*a + ctrlpoints[i][0]*b + ctrlpoints[i+1][0]*c + ctrlpoints[i+2][0]*d);		 besy = (ctrlpoints[i-1][1]*a + ctrlpoints[i][1]*b + ctrlpoints[i+1][1]*c + ctrlpoints[i+2][1]*d);		 besz = (ctrlpoints[i-1][2]*a + ctrlpoints[i][2]*b + ctrlpoints[i+1][2]*c + ctrlpoints[i+2][2]*d);	}desenhaObj(2,besx,besy,besz,rotacao,3);

The "desenhaobj" method receives has args the number of the mesh, besier position x, and so on, rotation (calcultated in another place) and the size of the mesh.


Hope I've been helpfull.

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