Compare commits

...

1 Commits

Author SHA1 Message Date
Florian Rival
7b6f6e4683 Add body type selector actions to physics behaviors 2025-10-01 17:32:09 +02:00
4 changed files with 103 additions and 0 deletions

View File

@@ -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',

View File

@@ -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') {

View File

@@ -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',

View File

@@ -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;
}