Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Extensions/Physics2Behavior/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,27 @@ module.exports = {
.getCodeExtraInformation()
.setFunctionName('setKinematic');

aut
.addAction(
'SetBodyType',
_('Set body type'),
_('Set the body type of an object.'),
_('Set the body type of _PARAM0_ to _PARAM2_'),
_('Dynamics'),
'res/physics32.png',
'res/physics32.png'
)
.addParameter('object', _('Object'), '', false)
.addParameter('behavior', _('Behavior'), 'Physics2Behavior')
.addParameter(
'stringWithSelector',
_('Body type'),
'["Static", "Dynamic", "Kinematic"]',
false
)
.getCodeExtraInformation()
.setFunctionName('setBodyType');

aut
.addCondition(
'IsBullet',
Expand Down
15 changes: 15 additions & 0 deletions Extensions/Physics2Behavior/physics2runtimebehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,21 @@ namespace gdjs {
return this.bodyType === 'Kinematic';
}

setBodyType(bodyType: string): void {
switch (bodyType) {
case 'Static':
this.setStatic();
break;
case 'Kinematic':
this.setKinematic();
break;
case 'Dynamic':
default:
this.setDynamic();
break;
}
}

setKinematic(): void {
// Check if there is no modification
if (this.bodyType === 'Kinematic') {
Expand Down
21 changes: 21 additions & 0 deletions Extensions/Physics3DBehavior/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,27 @@ module.exports = {
.getCodeExtraInformation()
.setFunctionName('isKinematic');

aut
.addScopedAction(
'SetBodyType',
_('Set body type'),
_('Set the body type of an object.'),
_('Set the body type of _PARAM0_ to _PARAM2_'),
_('Dynamics'),
'JsPlatform/Extensions/physics3d.svg',
'JsPlatform/Extensions/physics3d.svg'
)
.addParameter('object', _('Object'), '', false)
.addParameter('behavior', _('Behavior'), 'Physics3DBehavior')
.addParameter(
'stringWithSelector',
_('Body type'),
'["Static", "Dynamic", "Kinematic"]',
false
)
.getCodeExtraInformation()
.setFunctionName('setBodyType');

aut
.addScopedCondition(
'IsBullet',
Expand Down
46 changes: 46 additions & 0 deletions Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,52 @@ namespace gdjs {
return this.bodyType === 'Kinematic';
}

setBodyType(bodyType: string): void {
if (
bodyType !== 'Static' &&
bodyType !== 'Dynamic' &&
bodyType !== 'Kinematic'
) {
return;
}

if (this.bodyType === bodyType) {
return;
}

this.bodyType = bodyType;

if (this._body === null) {
if (!this._createBody()) return;
}

if (this._body === null) {
return;
}
const body = this._body!;
const bodyInterface = this._sharedData.bodyInterface;
let motionType: Jolt.EMotionType;
switch (this.bodyType) {
case 'Static':
motionType = Jolt.EMotionType_Static;
break;
case 'Kinematic':
motionType = Jolt.EMotionType_Kinematic;
break;
case 'Dynamic':
default:
motionType = Jolt.EMotionType_Dynamic;
break;
}

bodyInterface.SetMotionType(
body.GetID(),
motionType,
Jolt.EActivation_Activate
);
bodyInterface.SetObjectLayer(body.GetID(), this.getBodyLayer());
}

isBullet(): boolean {
return this.bullet;
}
Expand Down