1

I cannot combine the horizontal movement of the wheels with the vertical movement.

Additionally, the wheels only move forward. I have no idea how to check if the vehicle is moving forward or backward in order to be able to properly handle the movement of the wheels.

Watch the video: https://youtu.be/NDMsXG6lmc8

How it looks from the code side:

Turning the wheels horizontally:

  • The function is run after pressing the "a" or "d" key
  • The deg variable takes values {0, Math.PI / 8}
const steeringWheels = (deg) => {
    options.vehilce.wheelFrontOponaLeft.rotation.z = deg;
    options.vehilce.wheelFrontFelgaLeft.rotation.z = deg;
    options.vehilce.wheelFrontFelgaRight.rotation.z = deg;
    options.vehilce.wheelFrontOponaRight.rotation.z = deg;
}

Rotating the wheels vertically

  • Function called when each frame is rendered
const moveVehicle = (delta) => {
    options.vehilce.model.position.copy(options.vehilce.cannon.chassisBody.position.clone().vadd(new CANNON.Vec3(0, -.2, 0)));
    options.vehilce.model.quaternion.copy(options.vehilce.cannon.chassisBody.quaternion);

    angularVelocity = options.vehilce.cannon.wheelBodies[0].angularVelocity.length();

    options.vehilce.wheelFrontFelgaLeft.rotateX(angularVelocity * delta);
    options.vehilce.wheelFrontFelgaRight.rotateX(angularVelocity * delta);
    options.vehilce.wheelFrontOponaLeft.rotateX(angularVelocity * delta);
    options.vehilce.wheelFrontOponaRight.rotateX(angularVelocity * delta);
    options.vehilce.wheelBackFelgaLeft.rotateX(angularVelocity * delta);
    options.vehilce.wheelBackFelgaRight.rotateX(angularVelocity * delta);
    options.vehilce.wheelBackOponaLeft.rotateX(angularVelocity * delta);
    options.vehilce.wheelBackOponaRight.rotateX(angularVelocity * delta);
}

You can check out the full code here: https://github.com/kwiatu-dev/sphere-collision/tree/feature

To run the project, type:

  1. npm install
  2. parcel

I would like to be able to properly control the movement of the wheels while the vehicle is moving. If you are able to help me, please help.

Feel free to review the code and give me any tips. I'm just starting to learn.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.