I am trying to move an object along a path in Three.js. I'd like to build the path in a 'constructed' way, using the Path
object like this:
var path = new THREE.Path([
new THREE.Vector2(0, 0),
new THREE.Vector2(0, inDistance)
]);
path.arc(arcRadius, 0, arcRadius,
Geo.rad(180), Geo.rad(90), true);
path.lineTo(arcRadius + outDistance, arcRadius + inDistance);
Then I could use path.getPoint(t)
and path.getTangent(t)
to get an updated position for my object:
let position = path.getPoint(percentTraveled);
let tangent = path.getTangent(percentTraveled);
state.model.position.x = position.x;
state.model.position.y = position.y;
There are two problems with this:
- Path is only 2D
- The Path object can't be translated to the location and orientation of the object, so the positions / and tangents returned are absolute positions.
I've read this question, which discusses how to use a SplineCurve3
to move along a path, but this solution doesn't explain how to build a spline constructed from a set of lines and arcs.
How do you do that?