three.jsphysijs

Rotation When Object is Spinning


[] []

Imagine those are the front tires of a car and they're spinning forward in a straight line. How would I rotate them (in a steering motion) without them being affected by their local (spinning) rotation?


Solution

  • Add a "wheel" to a THREE.Group() object and rotate the group on y-axis.

      for(var i = 0; i < wheels.length; i++){
        steering[i].rotation.y = Math.sin(new Date() * 0.005) * 0.25;
        wheels[i].rotation.x += 0.1;
      }
    

    each steering is a THREE.Group(), each wheels is a cylinder.

    jsfiddle example