diff --git a/Extensions/Physics3DBehavior/JsExtension.js b/Extensions/Physics3DBehavior/JsExtension.js index d994584a922e..3118f0affa9e 100644 --- a/Extensions/Physics3DBehavior/JsExtension.js +++ b/Extensions/Physics3DBehavior/JsExtension.js @@ -990,6 +990,69 @@ module.exports = { ) .setFunctionName('getLinearVelocityLength'); + aut + .addExpressionAndConditionAndAction( + 'number', + 'AngularVelocityX', + _('Angular velocity X'), + _('the object angular velocity on X.'), + _('the angular velocity on X'), + _('Velocity'), + 'JsPlatform/Extensions/physics3d.svg' + ) + .addParameter('object', _('Object'), '', false) + .addParameter('behavior', _('Behavior'), 'Physics3DBehavior') + .useStandardParameters( + 'number', + gd.ParameterOptions.makeNewOptions().setDescription( + _('Angular speed (in degrees per second)') + ) + ) + .setFunctionName('setAngularVelocityX') + .setGetter('getAngularVelocityX'); + + aut + .addExpressionAndConditionAndAction( + 'number', + 'AngularVelocityY', + _('Angular velocity Y'), + _('the object angular velocity on Y.'), + _('the angular velocity on Y'), + _('Velocity'), + 'JsPlatform/Extensions/physics3d.svg' + ) + .addParameter('object', _('Object'), '', false) + .addParameter('behavior', _('Behavior'), 'Physics3DBehavior') + .useStandardParameters( + 'number', + gd.ParameterOptions.makeNewOptions().setDescription( + _('Angular speed (in degrees per second)') + ) + ) + .setFunctionName('setAngularVelocityY') + .setGetter('getAngularVelocityY'); + + aut + .addExpressionAndConditionAndAction( + 'number', + 'AngularVelocityZ', + _('Angular velocity Z'), + _('the object angular velocity on Z.'), + _('the angular velocity on Z'), + _('Velocity'), + 'JsPlatform/Extensions/physics3d.svg' + ) + .addParameter('object', _('Object'), '', false) + .addParameter('behavior', _('Behavior'), 'Physics3DBehavior') + .useStandardParameters( + 'number', + gd.ParameterOptions.makeNewOptions().setDescription( + _('Angular speed (in degrees per second)') + ) + ) + .setFunctionName('setAngularVelocityZ') + .setGetter('getAngularVelocityZ'); + // Forces and impulses aut .addScopedAction( diff --git a/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts b/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts index 22bf245414fe..6ad44e17080b 100644 --- a/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts +++ b/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts @@ -1317,6 +1317,81 @@ namespace gdjs { return body.GetLinearVelocity().Length() * this._sharedData.worldScale; } + getAngularVelocityX(): float { + if (this._body === null) { + if (!this.createBody()) return 0; + } + const body = this._body!; + + return body.GetAngularVelocity().GetX() * this._sharedData.worldScale; + } + + setAngularVelocityX(angularVelocityX: float): void { + if (this._body === null) { + if (!this.createBody()) return; + } + const body = this._body!; + + this._sharedData.bodyInterface.SetAngularVelocity( + body.GetID(), + this.getVec3( + angularVelocityX * this._sharedData.worldInvScale, + body.GetAngularVelocity().GetY(), + body.GetAngularVelocity().GetZ() + ) + ); + } + + getAngularVelocityY(): float { + if (this._body === null) { + if (!this.createBody()) return 0; + } + const body = this._body!; + + return body.GetAngularVelocity().GetY() * this._sharedData.worldScale; + } + + setAngularVelocityY(angularVelocityY: float): void { + if (this._body === null) { + if (!this.createBody()) return; + } + const body = this._body!; + + this._sharedData.bodyInterface.SetAngularVelocity( + body.GetID(), + this.getVec3( + body.GetAngularVelocity().GetX(), + angularVelocityY * this._sharedData.worldInvScale, + body.GetAngularVelocity().GetZ() + ) + ); + } + + getAngularVelocityZ(): float { + if (this._body === null) { + if (!this.createBody()) return 0; + } + const body = this._body!; + + return body.GetAngularVelocity().GetZ() * this._sharedData.worldScale; + } + + setAngularVelocityZ(angularVelocityZ: float): void { + if (this._body === null) { + if (!this.createBody()) return; + } + const body = this._body!; + + this._sharedData.bodyInterface.SetAngularVelocity( + body.GetID(), + this.getVec3( + body.GetAngularVelocity().GetX(), + body.GetAngularVelocity().GetY(), + angularVelocityZ * this._sharedData.worldInvScale + ) + ); + } + applyForce( forceX: float, forceY: float,