javascript - Raycasting direction relative to global coordinate system , not local -
i have used raycasting method detect different colored strips on either side of track , keeping car object in position calculating distance. problem ray points in constant direction in global coordinate system , doesnt change movement(rotation) of car object. have if ray direction in reference frame of car not able figure out how do. doing this
var ray = new three.raycaster(car.position, new three.vector3(-1,0,0),0,50);
the movement of car in x-z plane
can point out solution ?
your ray-casting being done in world-space, need correct world-space vector.
i assuming car child of scene, , not other rotated object.
to construct unit vector points in direction car heading in world coordinate system, first construct unit vector points in direction car heading in it's local coordinate system -- whatever happens in case:
var vector = new three.vector3( -1, 0, 0 );
then apply same rotation vector applied car.
vector.applyquaternion( car.quaternion );
edit: updated three.js r.66
Comments
Post a Comment