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.

http://filmsbykris.com/scripts/Game-Basics/BabylonJS/Enemies/maze_2.html

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.

##### Share on other sites

It would be a good idea to define paths using bezier curves. This is quite powerfull, theres a tutorial. http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/

##### Share on other sites

Kilombo,

So what you are saying is that there is currently no function in Babylonjs (as far as you know) that does this and if I want to do it I'll have to write my own function.
Is that correct?

##### Share on other sites

Correct. But check our roadmap, we have this point on it:)

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

##### Share on other sites

Deltakosh, good to hear.

Kilombo, thanks for the help.  I'll play around with this.

##### Share on other sites

Personnally I used TweenLite and TimelineLite to move my BabylonJs camera.  There is a cool bezier plugin.

Look at this example which inspired me http://codepen.io/GreenSock/pen/zcmpo.

It was done with tweenMax which is'nt free but bezier plugin work also with tweenLite (free version).

##### Share on other sites

Here is a little demo for you.

http://jsfiddle.net/7hxQq/1/

Hope it will help you !

##### Share on other sites

thanks Kostar111  I'll play around with that.

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

Loading...
×
• ### Recently Browsing   0 members

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