To easily control the rotation of your car Mesh in relation to the ground Mesh, simply nest the car inside the ground so that the rotations are inherited from parent to child. This way, you can manipulate the parent's rotation to mimic the slope of the ground and focus on rotating the car around its local y-axis without the need for additional calculations.
Check out this straightforward demonstration:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 200);
camera.position.z = 75;
// Additional code for creating renderer, controls, axes, ground plane, car, etc.
function animate(time) {
// Rotate the car around its own y-axis
car.rotation.y += 0.005;
// Make the ground plane sway back and forth
slope.rotation.z = Math.sin(time * 0.001) * 0.5;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate(0);
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://rawgit.com/mrdoob/three.js/dev/examples/js/controls/OrbitControls.js"></script>
<canvas id="canvas"></canvas>
If you prefer nesting the car inside an empty object, you can place it within a Group
.