CannonJS joint collision-flag problem... and more

Ok, what the heck, I wandered off-topic last post, let’s do it once more.

https://playground.babylonjs.com/index.html#RLKVFF#113

Back to a motorEnabled hinge joint on bounding-boxed leg1 (see line 168).

All the leg1 motor fun is happening at lines 488-508. I have included 3 different ways to run joint1 motor (to lift leg1 - after 3 seconds).

Now, I need this ‘motorized landing-gear-folding/unfolding’… to happen real slow. You’ll notice that all 3 methods of motor-running… use 0.4 motorSpeed. Two of the three methods use a motor maxForce of 50000. The last way… the pure-native way, uses maxForce = 3 (and minForce = -3).

Leg1 has a mass of .3… fairly insignificant weight.

Activate/disable various motor-running ways (and then re-run)… but notice that NONE of them… has enough maxForce… to completely lift leg1… to vertical and beyond. Not until you increase the motorSpeed to about 0.6… does the motor have enough maxForce to fully lift the leg.

No matter if maxForce is set to 3 or set to 50000, the motor cannot completely lift the leg… when motor speed is 0.4 or below.

For the actual project, I likely need motor speed around 0.2… and NO motor slippage/weakness.

So, I got problems. It’s likely that I don’t understand motor maxForce… but… according to what I’m seeing right now… maxForce is just “NOT pulling its weight”. :slight_smile: Ideas welcome.

Sorry for off-topic… but not really. I don’t know where (on the forum) to chronicle my on-going projects… to share what I learn. So, I grab every sneaky opportunity I can find… like at the bottom of a bugs thread. :slight_smile:

It seems (via some tests)… that I can attach springs to all leg-segments (only 1 segment so far)… and then animate their mainPivot locations and spring length/restLengths… to simulate multiple hinge-motors… unfolding a multi-segment landing gear leg. It is like using multiple invisible springs… as if they were puppet strings. But motors would be easier… and cooler, I suspect. For this project, the motors need to be super-slow, and very powerful… and so far… I have failed to fig how to do that.

It is likely that springs and motors don’t mix real well. Motors need to free-wheel and not be held-back by spring tensions. So, likely, during landing gear un-fold, there would not be springs on any bodies… so the motors can work smoothly. Then, after all unfold-motors finish, carefully add springs between all leg segment (bones), with precisely-set pivotpoints and restLengths… so the landing gear can become impact-“bouncy”… in the way we all love so much. :slight_smile:

What we REALLY need… is a “springy motor”… it acts like a hinge-spring when it isn’t running… with all the delicious spring settings… like stiffness, damping, frequency, whatever. SpringyMotorEnabledHingeJoint v1.0 YUM!!! sigh.

Another way… use standard animation on non-physics leg-mesh, and then add physics after they are finished unfolding (deploying). But… in doing that… we lose something. Pretend we’re coming-in for a landing a bit too fast (descent-wise), and the landing gear hasn’t finished deploying… when you hit the landing pad. POOM! We want that accident to look physics-yummy, right? You bet. Gotta have physics active on the landing gear pieces… when we kiss the concrete. :slight_smile: (if possible)

And, I HOPE there is a way to know WHEN to shut-off the motor… when the leg-segment/motor reaches a certain angle/rotation. I don’t see an easy way to do that… in CannonJS, either. OimoJS motors have .upperLimit and .lowerLimit values (set in degrees, I believe).

Moving the spring’s pivot locations (spring localAnchorA and B) on-the-fly… didn’t work, but adjusting .restLength on-the-fly… DOES work! Yay! https://playground.babylonjs.com/index.html#RLKVFF#117

No motors during this leg1 “fold-up” attempt. See lines 499/500 (they are inside renderLoop). They are slowly reducing the joint5 (a spring) .restLength. This “sucks” (the connectedPivot towards the mainPivot)! It gives a nice gentle fold-up… WITH a usable “when to stop” indicator (when .restLength hits zero or some other value).

Not bad. Puppet string-springs… reduce the puppet string length for the leg… ENOUGH… and it will lift the leg up-to the puppet’s head, eh? Fascinating! (yawn). Motorizing… without motors. yeah! :slight_smile:

#118 folds-up and down, back and forth, real slow… all done with lines 501-512. So cool.

Using setAngularVelocity on the leg1 impostor… WHILE spring still attached… is being tested, too. Not good results, so far. Difficult to know when to shut it off, and the rotation fights-with spring tension.

With this no-motors springs-active-constantly system (not needing to disable springs so that deploy/retract motors work smoothly)… we should have nice, ugly lander accidents, IF pilot descends too fast, not allowing enough time for the landing gear to fully deploy. It should be plenty bouncy and the half-deployed landing gear should smack the ground deliciously, sending the lander into unpredictable rotations and translations (out-of-controlism). I like that idea. :slight_smile:

Don’t worry… space station docking is even MORE miserable. :slight_smile: Coming soon to an orbiter near you.

Are all zero of this project’s followers… asleep yet? Let’s hope so. :slight_smile:

Ok, let’s bring this topic back on track.

First, a note in the impostor.setMass source code: Specifically change the body’s mass option. Won’t recreate the physics body object Yet, setMass() calls this.setParam(“mass”, mass); … a function just above that line of the source.

Let’s look at setParam()… either in the source, or in this playground…

https://playground.babylonjs.com/#RLKVFF#124 (lines 15-20)

setParam() includes this line: this._bodyUpdateRequired = true; This makes “Won’t recreate the physics body object” an incorrect statement.

Line 17 is a testing line (and mod recommendation) that I added, which we will test soon.

2 seconds after scene-ready, I use setMass() at line 135… to change greenbox mass from 0.5 to 0.1. As you can see, things go to hell at the 2-second mark (during greenbox fall).

Now activate line 17 and re-run. Things are acting better.

Just to prove things, disable line 135 setMass() call. Activate line 134, which is the OTHER way of setting mass. It acts the same. (same-as using setMass with active line 17).

I’m no core-grade coder, and I have a real difficult time seeing far-reaching impacts of a core mod, so I leave it to the pros/paids. I think… line 17 should be added to BABYLON.PhysicsImpostor.setParam().

I would appreciate it… if experts reviewed this idea THOROUGHLY, and if sane, somebody make the mod for us. I don’t want to add the mod myself, because I’m not qualified to mod core, and I’m not willing to step into the line-of-fire when things go wrong. There’s already plenty-of “fingers in the pie” of BJS physics objects/systems.

This is my recommendation, but it is not necessarily a wise recommendation… until after thorough peer review and approval. Thanks!

BEWARE: This mod/impostor-class is used by ALL physics engines which are honored by BJS… I believe. (Help me…) Carefully check-for FRR, please. (far-reaching ramifications)

If anyone needs help tracing ._bodyUpdateRequired to line 99 of plugin, just holler.

To be frank, I wish we would/could work REAL HARD to NEVER need a body init, not even if the shape is scaled on-the-fly (which was MAYBE the ONLY reason body init was invented/thought-up). @RaananW MAY know the answer to that question. Got time for a quick comment, R-man? (thx)

Side note: Remember when Raanan took too many anti-gravity pills… during the BJS poker tournament? He hired some girl… to keep him from floating out of the chair. THAT was pretty funny, eh?

(Sorry Raanan… I know I used that pic for comedy once before… but it STILL has lots of potential for more) :slight_smile: PM me if you want my link/comedy-attempt… removed - np.

Ping @Cedric :slight_smile:

Cedric probably pretty-much hates me, by now. :slight_smile:

------------------ off topic --------------------
4-leg landing gear retract/deploy (toggling automatically, so far)… using no motors and only spring restLengths… https://playground.babylonjs.com/#RLKVFF#126

New keypresses… ‘a’ to activate mass on greenbox, ‘h’ to hover (remove mass)… and ‘L’ is still “launch” or “lift”. Repeated short taps of “L” helps keep lander level during liftoff. Holding the “L” key doesn’t level the lander… just makes it take off at current lander orientation.

Under certain conditions, legs will fold-up in the wrong direction. Shortening/lengthening .restLengths on springs… to fold/unfold the gear… has its issues. The legs ALWAYS fold “under”… when the legs are hanging from a hovering lander (legs are dropped downward a bit, due to their mass and world gravity).

When legs are folded AFTER lander has landed (after ‘A’ key pressed to add mass)… the legs are pushed UPWARD a bit, and restLength shortening… will retract the legs UPWARD in that case. Still studying that. :slight_smile:

Stunning Proclaimation: Using restLength “scaling” to move hinge joints… is ALWAYS “a 180-degree thing”. Ending the spring’s restLength at a length… where the hinge is at a position > 0 && < 180 (relative to spring angle)… can make the spring act unpredictable. You might quick-think that upperLimit and lowerLimit on hinge joint… would be useful. But those are “hard stops” and will cause our spring-loaded hinge joint… to not “swing” properly. This is why we need… the spring-loaded hinge joint to be ONE thing… a special kind of joint… much like a starter-rope “recoil” on mowers/small engines. The restLength and pivotPoints would act-upon the coil spring (much like a pocket-watch main-spring). Damping and stiffness also active, of course. Oh @Schteppe… are ya busy? :slight_smile:

Has anyone invited him to the new forum, yet? He’ll build us the worlds first (motor-enabled) springy-hinge joint… I know he will. :slight_smile: The motor will be able to operate on this new joint’s HINGE, OR… it can be used to coil/uncoil the wraps of the spring AROUND the hinge-axis (circularly spinning spring’s main anchor-point). COOL, huh? Or maybe a separate motor for each usage, so BOTH motors (spring motor and hinge motor) can run at the same time! COOOOOOL! CoilSpringMotor vs. HingeMotor… should be a good fight. :slight_smile:

Fun extra: Change the 4 springs’ attach point on the green box (line 230) to -7 (lower on the greenbox), and the gear retract/deploy… acts differently.

Nah i do not think so, this is always good to have more feedback :wink:

1 Like

@Wingnut I like when you ask questions and push the boundaries. It’s the best way to make good software. So, thank you for taking time to thoroughly test and experiment with Babylon.

Yes, that impostor class is used by every physics engine. Any change in that file must be carefully tested.

2 Likes

Cool, I’m glad you agree, and thx for kind words. (hug)

Perhaps… to be helpful, I went searching for all occurrences of setMass() in our pg-db. 33 returns… most were Cannon-related, many were impertinent, but SOME… were setMass() happenings in AmmoJS and/or OimoJS… which are good post-mod test PG’s for us. Here they are:

https://www.babylonjs-playground.com/#1HQ6AN#0 - an OIMO p-demo with a setMass(). Good starter for post-mod Oimo-breakage tests.

https://www.babylonjs-playground.com/#24JRLD#7 - Broken/outdated, but notice comments @114 regarding impostor disconnecting from its joints after a Cannon setMass() call. Same problem I’m having, somewhat. This issue has been nearby and unsolved… since the days of setPhysicsState()… back when we computed on cave walls. heh.

https://www.babylonjs-playground.com/#5W5B6W#61 - Ignore this. I was just reminiscing about the old (8 months ago?) stuttering-motor issue with Oimo. I dunno where that issue stands, currently. Hanging, I think. :slight_smile: @Cedric - if you want the scoop, notice line 108… motor speed 3, maxForce 6… in Ammo works perfect. Change to Oimo in line 84, and now it takes a maxForce of around 8000 or more… to get “Stutterin’ Stacy” to move at all. What’s that? Yeah, I KNEW you wanted to be included in this one. I, and JohnK, and TrevorDev, and others… chased that issue until we were exhausted. Elusive. I smelled some bad stink near the setBiDirectionalTransformWhatever property, but I could never prove that anything was rotten, there. In my shoddy opinion, Stutterin’ Stacy arrived about the same time as transformNodes were added to BJS. Don’t put much ‘mass’ on that theory, though. :slight_smile: There’s a thousand-post thread about it… laying around here somewhere. :slight_smile:

https://www.babylonjs-playground.com/#B5BDU#71 - the AmmoJS series we’re working-on in another thread.

https://www.babylonjs-playground.com/#BXII#77 - An AmmoJS PG with a setMass. Good after-mod tester, maybe.

https://www.babylonjs-playground.com/#CFL148#34 - A nasty Ammo rope-impostor buttons-hanging-from-chains thing I tested… lots of setMass calls, but all remarked-out.

https://www.babylonjs-playground.com/#NYSAHQ#8 - door opener/closer I recently worked-on with friends. A couple of setMass calls happen in this AmmoJS pg.

https://www.babylonjs-playground.com/#UB5VZ3#1 - drag/drop tests with setMass on AmmoJS. Another good-lookin after-mod tester.