Bullet Vehicle doesn't move

Hello, I just knocked up this for vehicle bullet in C++ but my vehicle doesn’t move even after applying engine force. I’m sure when I last did this the code was pretty much the same and it did move, albeit weirdly. I wonder if I mucked up the wheels or something.

#include “pandaFramework.h”
#include “windowFramework.h”
#include “nodePath.h”
#include “clockObject.h”

#include “asyncTask.h”
#include “genericAsyncTask.h”

#include “bulletWorld.h”
#include “bulletPlaneShape.h”
#include “bulletBoxShape.h”
#include “bulletVehicle.h”
#include “bulletWheel.h”
#include “bulletDebugNode.h”

BulletWorld* get_physics_world() {
// physics_world is supposed to be an global variable,
// but declaring global variables is not cool
// for good programmers lol, instead, should use static keyword.
static PT(BulletWorld) physics_world = new BulletWorld();
return physics_world.p();
}

AsyncTask::DoneStatus update_scene(GenericAsyncTask* task, void* data) {
// Get dt (from Python example) and apply to do_physics(float, int, int);
ClockObject* co = ClockObject::get_global_clock();
get_physics_world()->do_physics(co->get_dt(), 10, 1.0 / 180.0);

return AsyncTask::DS_cont;

}

BulletDebugNode* get_physics_debug_node() {
// Global variable.
static BulletDebugNode* bullet_dbg_node = new BulletDebugNode(“Debug”);
return bullet_dbg_node;
}

int main(int argc, char* argv[]) {
// All variables.
PandaFramework framework;
WindowFramework* window;
NodePath camera;
PT(AsyncTaskManager) task_mgr;

// Init everything :D
framework.open_framework(argc, argv);
framework.set_window_title("Bullet Physics");

window = framework.open_window();
window->enable_keyboard();
window->setup_trackball();

camera = window->get_camera_group();
task_mgr = AsyncTaskManager::get_global_ptr();

// Make physics simulation.
// Static world stuff.
get_physics_world()->set_gravity(0, 0, -9.81f);

PT(BulletPlaneShape) floor_shape = new BulletPlaneShape(LVecBase3(0, 0, 1), 1);
PT(BulletRigidBodyNode) floor_rigid_node = new BulletRigidBodyNode("Ground");

floor_rigid_node->add_shape(floor_shape);

NodePath np_ground = window->get_render().attach_new_node(floor_rigid_node);
np_ground.set_pos(0, 0, -2);
get_physics_world()->attach(floor_rigid_node);

//Debug renderer
PT(BulletDebugNode) bullet_dbg_node;
bullet_dbg_node = new BulletDebugNode("Debug");
bullet_dbg_node->show_bounding_boxes(true);
bullet_dbg_node->show_constraints(true);
bullet_dbg_node->show_normals(true);
bullet_dbg_node->show_wireframe(true);

NodePath np_dbg_node = window->get_render().attach_new_node(get_physics_debug_node());
np_dbg_node.show();

get_physics_world()->set_debug_node(get_physics_debug_node());

// Chassis body
PT(BulletBoxShape) shape = new BulletBoxShape(LVecBase3(0.7, 1.5, 0.5));
TransformState::make_pos(LPoint3(0, 0, 0.5));
PT(BulletRigidBodyNode) vehicle_rigid_node = new BulletRigidBodyNode("Vehicle");
NodePath np_chassis = window->get_render().attach_new_node(vehicle_rigid_node);
vehicle_rigid_node->add_shape(shape);
np_chassis.set_pos(0, 0, 1);
vehicle_rigid_node->set_mass(800.0);
vehicle_rigid_node->set_deactivation_enabled(false);
get_physics_world()->attach(vehicle_rigid_node);

//Vehicle
PT(BulletVehicle) vehicle = new BulletVehicle(get_physics_world(), vehicle_rigid_node);
vehicle->set_coordinate_system(BulletUpAxis::Z_up);
get_physics_world()->attach_vehicle(vehicle);

//Wheels

//Front R wheel
BulletWheel wheel = vehicle->create_wheel();
wheel.set_chassis_connection_point_cs(LPoint3(0.8, 1.1, 0.3));
wheel.set_front_wheel(true);
wheel.set_wheel_direction_cs(LVecBase3(0, 0, -1));
wheel.set_wheel_axle_cs(LVecBase3(1,0,0));
wheel.set_wheel_radius(0.25);
wheel.set_max_suspension_travel_cm(40.0);
wheel.set_suspension_stiffness(40.0);
wheel.set_wheels_damping_relaxation(2.3);
wheel.set_wheels_damping_compression(4.4);
wheel.set_friction_slip(100.0);
wheel.set_roll_influence(0.1);

//Front L wheel
BulletWheel wheel2 = vehicle->create_wheel();
wheel2.set_chassis_connection_point_cs(LPoint3(-0.8, 1.1, 0.3));
wheel2.set_front_wheel(true);
wheel2.set_wheel_direction_cs(LVecBase3(0, 0, -1));
wheel2.set_wheel_axle_cs(LVecBase3(-1, 0, 0));
wheel2.set_wheel_radius(0.25);
wheel2.set_max_suspension_travel_cm(40.0);
wheel2.set_suspension_stiffness(40.0);
wheel2.set_wheels_damping_relaxation(2.3);
wheel2.set_wheels_damping_compression(4.4);
wheel2.set_friction_slip(100.0);
wheel2.set_roll_influence(0.1);

//Rear R wheel
BulletWheel wheel3 = vehicle->create_wheel();
wheel3.set_chassis_connection_point_cs(LPoint3(0.8, -1.1, 0.3));
wheel3.set_front_wheel(true);
wheel3.set_wheel_direction_cs(LVecBase3(0, 0, -1));
wheel3.set_wheel_axle_cs(LVecBase3(1, 0, 0));
wheel3.set_wheel_radius(0.25);
wheel3.set_max_suspension_travel_cm(40.0);
wheel3.set_suspension_stiffness(40.0);
wheel3.set_wheels_damping_relaxation(2.3);
wheel3.set_wheels_damping_compression(4.4);
wheel3.set_friction_slip(100.0);
wheel3.set_roll_influence(0.1);

//Rear L wheel
BulletWheel wheel4 = vehicle->create_wheel();
wheel4.set_chassis_connection_point_cs(LPoint3(-0.8, -1.1, 0.3));
wheel4.set_front_wheel(true);
wheel4.set_wheel_direction_cs(LVecBase3(0, 0, -1));
wheel4.set_wheel_axle_cs(LVecBase3(-1, 0, 0));
wheel4.set_wheel_radius(0.25);
wheel4.set_max_suspension_travel_cm(40.0);
wheel4.set_suspension_stiffness(40.0);
wheel4.set_wheels_damping_relaxation(2.3);
wheel4.set_wheels_damping_compression(4.4);
wheel4.set_friction_slip(100.0);
wheel4.set_roll_influence(0.1);

// Steering info
PN_stdfloat steering = 1.0;
PN_stdfloat engineForce = 1000.0;

// Apply steering to front wheels
vehicle->set_steering_value(steering, 0);
vehicle->set_steering_value(steering, 1);

// Apply engineand brake to rear wheels
vehicle->apply_engine_force(engineForce, 2);
vehicle->apply_engine_force(engineForce, 3);
vehicle->set_brake(0, 2);
vehicle->set_brake(0, 3);

PT(GenericAsyncTask) task;
task = new GenericAsyncTask("Scene update", &update_scene, nullptr);
task_mgr->add(task);

framework.main_loop();
framework.close_framework();

return (0);

}

Never mind I found the issue. I was using this:

TransformState::make_pos(LPoint3(0, 0, 0.5));
vehicle_rigid_node->add_shape(shape);

Which obviously doesn’t add the transform state to the vehicle node, so changing it to

ConstPointerTo ts = TransformState::make_pos(LVecBase3(0, 0, 0.5));
vehicle_rigid_node->add_shape(shape,ts);

fixed the issue.

Cheers,