mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add body type selector actions to physics behaviors
This commit is contained in:
@@ -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',
|
||||
|
@@ -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') {
|
||||
|
@@ -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',
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user