# Final path3D position and rotation

**URL:** <https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232>\
**Category:** Questions\
**Tags:** animation, path3d, points\
**Created:** [February 14, 2023, 11:30pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232 "2023-02-14T23:30:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [February 14, 2023, 11:30pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/1 "2023-02-14T23:30:09Z")

</div>

How can we make the final Path3D position and rotation the same as the initial of the mesh (box)?

⚠ double click to start animation

> **[Babylon.js Playground](https://playground.babylonjs.com/#DPISMX%234)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 15, 2023, 11:33am UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/2 "2023-02-15T11:33:58Z")

</div>

Hello! The last argument of the Catmull-Rom creation function allows you to make a closed curve: [Curve3 | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/typedoc/classes/BABYLON.Curve3#CreateCatmullRomSpline)

---

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [February 15, 2023, 11:44pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/3 "2023-02-15T23:44:29Z")

</div>

Hey @carolhmj , I tried this one before posting, but the initial/final position of the catmullRom changes (should be the same as the mesh):

 ![Screenshot from 2023-02-15 23-19-57](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/1/310266e8f76ff1e23f244608474c5b00a38bf0d7.png)

And, most of the time, the final rotation don’t match with the initial one:

> **[Babylon.js Playground](https://playground.babylonjs.com/#DPISMX%237)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

If we remove the rotationAnimation, without closed curve looks perfect:

> **[Babylon.js Playground](https://playground.babylonjs.com/#DPISMX%236)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I think the problem is how to rotate from 0 to any and return to 0 at the end:

- `0...1, 3, 2, 1...0`
- `0...N...0`

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [February 16, 2023, 12:03pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/4 "2023-02-16T12:03:25Z")

</div>

Hmmm then you’ll need a method to match the initial and final tangents of the curve (as the rotation is derived from them). I would possibly look into using a different type of curve for that that allows you to explicitly define your tangents, like the Hermite Spline: [Drawing Curves | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-spline)

---

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [February 16, 2023, 6:23pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/5 "2023-02-16T18:23:22Z")

</div>

😮 I haven’t tried this one. Thanks

---

<div class="post-metadata">

**Author:** ![jelster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jelster/32/25881_2.png) [@jelster](https://forum.babylonjs.com/u/jelster)\
**Post date:** [February 16, 2023, 7:54pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/6 "2023-02-16T19:54:44Z")

</div>

Space-Truckers had to solve this problem - it plagued me a long time indeed! See [The code repos](https://github.com/jelster/space-truckers) and look in the driving screen code for specifics

In that case, I started with a collection of point and corresponding world-absolute rotations and used Path3D along with a matrix rotation to project points around the path into a tube or a tunnel using Mesh.createRibbon.

When you create the Path3D it’s important to both note that the path represents points as floats between 0 and 1, and to pass appropriate parameters in the constructor to interpolate as needed and/or normalize points. Take care to decide whether you’ll want to work in local or world space xforms and check that you’re properly converting between where indicated

HTH - not at my laptop so a bit tough to get PG links, sorry!

---

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [February 17, 2023, 9:56pm UTC](https://forum.babylonjs.com/t/final-path3d-position-and-rotation/38232/7 "2023-02-17T21:56:12Z")

</div>

Pretty neat, @jelster! You have a heavy cargo. I’ll take a look at the load on these trucks 🚚  
Thanks man.
