Hi G. Essentially, linearVelocity IS a direction with magnitude, I think. Besides summing to be a single direction, it also contains the amount of x-velocity, and y-velocity, and z-velocity, yes?
How to USE IT as a direction (like to aim an arrow)? I have no idea. But others are nearby to help, perhaps. I’m pretty busy in real life at the moment… but soon will have more time.
Perhaps you need a vector3 that tells direction… even when player is sitting still and there’s NO linear velocity. Perhaps you want to thrust out-of the player’s butt, no matter which way they have turned, right? And it is difficult to calculate the “butt-thrust direction” when player is all rotated weird, huh? Yep, been there. Just in-case that is true…
… @deltakosh to the rescue. Look at the 304 p-box playground… lines 133-138. That’s what you need, or something real similar.
Now scroll up a few lines to 114-121 transPositiveZ function. Translate positive Z. That… is a fart (impulse) toward negative z, which would move our player positive z (local space to box).
Look at line 117.
var forcevec = this.doTransformPerFlyerQuat(new BABYLON.Vector3(0, 0, this.transforce));
transforce is a you-set power level. Main thing is… x and y values in that vec3… are 0. ONLY z has a magnitude.
When forcevec returns from doTransformPerFlyerQuat()… it is holding the correct direction for impulsing the box… localSpace z-ward. See line 129…
this.flyer.applyImpulse(forcevec, cntptloc);
There’s our “adjusted” forcevec being used for an impulse. It could be used for a setLinearVelocity(), too.
cntptloc is “contact point location” as you likely know. Almost everyone just uses box.getAbsolutePosition()
in that param (box center/origin/pivot-point).
If you used box.getAbsolutePosition().add(new BABYLON.Vector3(0, -1, 0))
… that would lower the contact point a bit… possibly making the box do a little “wheelie” when it was impulsed.
If you study 304 carefully, you’ll see that I do TWO impulses to spin the box… from two opposing sides of the box… and both using opposite “offsets”. Up in line 18… the master “turn force” is called this.offset. It is the AMOUNT of position offset-from-center that the two impulses use (their cntptloc). It can be ANY value, even if much more magnitude than thrusted mesh size. (Contact points can be positioned WAY OUT in space, a LONG ways from box center). Big “leverage” for teeter-totter fulcrum-fun.
Besides offset amounts, you can, of course, increase/decrease the magnitude of the forcevec. It might be wise to learn how to scale a vector3, because scaling your forcevec is the same as a power setting. Scale greater than factor 1, and power increases. Scale less than factor 1, and power reduces. Scaling NEVER likes negative numbers and unpredictable results could occur.
http://urbanproductions.com/wingy/babylon/misc/info01.jpg
(a little diagram of dual-impulse rotation)
The setAngularVelocity() func eliminates the need for dual impulsing to rotate. I need to update my flyer.
Ok that’s plenty for this one.
Good luck! Things are looking good.