I am very excited at the idea of using the Havok engine in my video game where my performance bottleneck is precisely related to Ammo.
I did not find any information on the motorization of physical constraints. I would need to induce velocity on a hinge-like and slider-like constraint as is possible in Ammo and Canon.
Is it possible? Is there an example or related documentation?
First of all, it seems that the API is only open for 6DOF constraints, which makes using motors difficult from the very beginning. Indeed, I would have expected to be able to simply do a setTargetVelocity() , setTargetPosition() or setForce() on simpler constraints such as a HingeJoint or a PrismaticJoint.
Is there a way to call native Havok functions to try this?
Is there an online API for Havok?
Iāve done a few tries starting with the main Havok example and the constraints example, but I canāt get the second solid to move using the motor related functions.
Here is my result on a 6DOF joint which looks like a distance constraint:
I wonder if anyone has a starting point that would allow me to start with this topic?
Weāve got a bug in HavokPlugin.setAxisMotorType() - weāre passing the motor type straight into the WASM; it needs to be converted to the ānativeā type, like we do for the axis ID.
I was able to workaround it in the playground by passing in the native type directly. Hereās a playground that I based on the above which shows how. I also modified the joint and shapes to make it a bit easier to see the effect of the motor. Iād definitely like to add some more interfaces to the simple joint types. As it is, they use the 6DOF interface under the hood, but in a limited way, to make them easier to setup.
Thank you very much for taking my issue into consideration.
I can now progress a lot with your workaround.
I worked several years in robotic simulations and I recommend you to open APIs to control prismatic and hinge constraints, in force, velocity and position modes. This covers 95% of the robotic cases. PID control would also be sugar.
If at some point I have a good sample to share, I will post it there.
I progress a lot with linear and angular constraints in my project, and itās working like a charm (even if 6DOF anchors and axes are a nightmare to setup).
Linear and rotational control in velocity and position seems to work well too.
I have now another issue: is there a way to retrieve the actual angle or position of a constraint? I need this feeedback to implement PID control.
Physics6DoFConstraint.getAxisMotorTarget() allow to get the last command, but not the actual position or angle feedback.
@eoin I probably have to call some Havok API directly?
Yes, this is what Iām doing now, so Iām not blocked with this.
But I expect that the physics engine has this data internally. So recomputing it is not efficient, and not so obvious. For example, a motor controlled in position can do several turns and can have values above 2*Pi. There are also issues with signs, etc. This is not simply a crossproduct.
Every physics engine I worked with have an access to this value, for example AMMO:
We donāt actually store those values in the engine (except in some special cases), so calculating it is definitely the way to go. I agree we should put in methods in the joints to calculate these so you donāt have to write that code.
As an aside, Ammo seems to sometimes calculate it, and sometimes use a stored value:
I donāt know anything about the Ammo implementation, but my gut feeling is that using a stored value is likely to give slightly incorrect results. I guess that sliderās stored value is set inside the solver; in a PGS solver, other constraints are able to modify the bodies after that value would have been computed, so it can be slightly wrong. It also probably doesnāt account for modifications to the body transforms after the solving has completed. Could be wrong on either of these, obviously, but just looked like something Iād be concerned about.
Also I see you said the 6DoF constraint was difficult to use. I spotted a bug last week where the āperpAxisā parameter was ignored, which might have been the cause of that? (Fix bug where constraint perp axes were ignored by eoineoineoin Ā· Pull Request #13859 Ā· BabylonJS/Babylon.js Ā· GitHub) If so, Iām real, real, REAL sorry. Very embarassing bug . If you had any ideas for how we could improve the documentation here, Iād love to incorporate them. All those constraint setup parameters feel quite natural to me, but Iāve been doing this fo a long time
Thank you very much for your answer.
I have to digest it, and I will come back later with this.
The bug you solved with the perpAxis may explain lot of my issues. Currently, I think there are bugs with 6DOFConstraints, when there are more than 4 DOF that are locked. I bet that itās precisely linked with perpAxisā¦
OMG, I confirm that the perpAxis bug was causing lot of issues in my project. Upgrading @babylonjs/core and using perpAxis properly allow me to do what I want with 6DOF constraints.