fabmax / physx-js-webidl

Javascript WASM bindings for Nvidia PhysX
MIT License
119 stars 28 forks source link

Cannot Use Character Controller Or Vehicles #35

Closed AntoineUserName closed 3 months ago

AntoineUserName commented 3 months ago

Hello, i need to use the Character Controller and the Vehicles but the classes just return an error:

new PhysX.PxController() and new PhysX.BaseVehicle() returns alls: "cannot construct a "class-name", no constructor in IDL"

I tried with the 2 different versions of physx-js-webidl and it's the same.

I have never used c++ before so if i need to compile the .wasm file i don't think i can do it.

fabmax commented 3 months ago

PxController and BaseVehicle are both abstract classes, you can't instantiate directly. For the character controller you need to create a controller manager first then create a PxCapsuleControllerDesc with the properties your controlelr should have. Then create the controller with the controller manager using your PxCapsuleControllerDesc. Something like this:

const scene = // create a scene first
...
const controllerManager = PhysX.PxTopLevelFunctions.prototype.CreateControllerManager(scene);

const controllerDesc = new PhysX.PxCapsuleControllerDesc();
// set controller properties to your liking, e.g. controllerDesc.set_height(1.5);

const controller = controllerManager.createController(controllerDesc);

The PhysX documentation might help as well: https://nvidia-omniverse.github.io/PhysX/physx/5.4.0/docs/CharacterControllers.html

For vehicle you have to create one of the subclasses of BaseVehicle. E.g. EngineDriveVehicle and then configure it as needed. However, in PhysX vehicles are pretty hard to set up correctly (There are a ton of parameters which need to be set correctly). So I would recommend starting with something simpler.

AntoineUserName commented 3 months ago

Thank you, i tried but finally i don't think that the character controller is really for what i need.

I maybe need to use another physic, for the vehicles you recommanded me to use something simpler.

I searched and there is ammojs and cannonjs but idk which one are the most optimised and i need a good vehicle physic, this vehicle physic need a friction attributes and everytime i found a vehicle physic for these physics libraries the vehicle have no frictions. So basically i need a vehicle physic that allow the vehicles to drift.

Do you know an optimised 3D physic that you can recommand to me?

fabmax commented 3 months ago

I haven't really tried other engines, so I don't know how good they are but ammojs seems to be quite popular. There is also joltPhysics.js which looks pretty good

AntoineUserName commented 3 months ago

I will test it, thank you