Skip to content

Commit

Permalink
Ass instructions for angular velocity.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Dec 5, 2024
1 parent 81b3c69 commit 1b1ea87
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Extensions/Physics3DBehavior/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
75 changes: 75 additions & 0 deletions Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1b1ea87

Please sign in to comment.