Skip to content

Commit

Permalink
Declare character properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Nov 21, 2024
1 parent 0921234 commit 7be8d2f
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 22 deletions.
241 changes: 237 additions & 4 deletions Extensions/Physics3DBehavior/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,95 @@ module.exports = {
return true;
}

if (propertyName === 'slopeMaxAngle') {
if (propertyName === 'JumpHeight') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('jumpHeight')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'JumpSustainTime') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('jumpSustainTime')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'Gravity') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent.getChild('gravity').setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'FallingSpeedMax') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('fallingSpeedMax')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'ForwardAcceleration') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('forwardAcceleration')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'ForwardDeceleration') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('forwardDeceleration')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'ForwardSpeedMax') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('forwardSpeedMax')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'SidewaysAcceleration') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('sidewaysAcceleration')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'SidewaysDeceleration') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('sidewaysDeceleration')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'SidewaysSpeedMax') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
.getChild('sidewaysSpeedMax')
.setDoubleValue(newValueAsNumber);
return true;
}

if (propertyName === 'SlopeMaxAngle') {
const newValueAsNumber = parseFloat(newValue);
if (newValueAsNumber !== newValueAsNumber) return false;
behaviorContent
Expand All @@ -1464,23 +1552,168 @@ module.exports = {
.addExtraInfo('Physics3D::Physics3DBehavior');

behaviorProperties
.getOrCreate('slopeMaxAngle')
.getOrCreate('JumpHeight')
.setLabel(_('Jump height'))
.setGroup(_('Jump'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixel())
.setValue(
behaviorContent.getChild('jumpHeight').getDoubleValue().toString(10)
);

behaviorProperties
.getOrCreate('JumpSustainTime')
.setLabel(_('Jump sustain time'))
.setQuickCustomizationVisibility(gd.QuickCustomization.Hidden)
.setGroup(_('Jump'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getSecond())
.setValue(
behaviorContent
.getChild('slopeMaxAngle')
.getChild('jumpSustainTime')
.getDoubleValue()
.toString(10)
)
.setDescription(
_(
'Maximum time (in seconds) during which the jump strength is sustained if the jump key is held - allowing variable height jumps.'
)
);

behaviorProperties
.getOrCreate('Gravity')
.setLabel(_('Gravity'))
.setGroup(_('Jump'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getDegreeAngle())
.setMeasurementUnit(gd.MeasurementUnit.getPixelAcceleration())
.setValue(
behaviorContent.getChild('gravity').getDoubleValue().toString(10)
);

behaviorProperties
.getOrCreate('FallingSpeedMax')
.setLabel(_('Max. falling speed'))
.setGroup(_('Jump'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelSpeed())
.setValue(
behaviorContent
.getChild('fallingSpeedMax')
.getDoubleValue()
.toString(10)
);

behaviorProperties
.getOrCreate('ForwardAcceleration')
.setLabel(_('Forward acceleration'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelAcceleration())
.setValue(
behaviorContent
.getChild('forwardAcceleration')
.getDoubleValue()
.toString(10)
);

behaviorProperties
.getOrCreate('ForwardDeceleration')
.setLabel(_('Forward deceleration'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelAcceleration())
.setValue(
behaviorContent
.getChild('forwardDeceleration')
.getDoubleValue()
.toString(10)
);

behaviorProperties
.getOrCreate('ForwardSpeedMax')
.setLabel(_('Max. forward speed'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelSpeed())
.setValue(
behaviorContent
.getChild('forwardSpeedMax')
.getDoubleValue()
.toString(10)
);

behaviorProperties
.getOrCreate('SidewaysAcceleration')
.setLabel(_('Sideways acceleration'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelAcceleration())
.setValue(
behaviorContent
.getChild('sidewaysAcceleration')
.getDoubleValue()
.toString(10)
)
.setAdvanced(true);

behaviorProperties
.getOrCreate('SidewaysDeceleration')
.setLabel(_('Sideways deceleration'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelAcceleration())
.setValue(
behaviorContent
.getChild('sidewaysDeceleration')
.getDoubleValue()
.toString(10)
)
.setAdvanced(true);

behaviorProperties
.getOrCreate('SidewaysSpeedMax')
.setLabel(_('Max. sideways speed'))
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getPixelSpeed())
.setValue(
behaviorContent
.getChild('sidewaysSpeedMax')
.getDoubleValue()
.toString(10)
)
.setAdvanced(true);

behaviorProperties
.getOrCreate('slopeMaxAngle')
.setLabel('Slope max. angle')
.setGroup(_('Walk'))
.setType('Number')
.setMeasurementUnit(gd.MeasurementUnit.getDegreeAngle())
.setValue(
behaviorContent
.getChild('slopeMaxAngle')
.getDoubleValue()
.toString(10)
)
.setAdvanced(true)
.setQuickCustomizationVisibility(gd.QuickCustomization.Hidden);

return behaviorProperties;
};

behavior.initializeContent = function (behaviorContent) {
behaviorContent.addChild('Physics3D').setStringValue('');
behaviorContent.addChild('jumpHeight').setDoubleValue(200);
behaviorContent.addChild('jumpSustainTime').setDoubleValue(0.2);
behaviorContent.addChild('gravity').setDoubleValue(1000);
behaviorContent.addChild('fallingSpeedMax').setDoubleValue(700);
behaviorContent.addChild('forwardAcceleration').setDoubleValue(1200);
behaviorContent.addChild('forwardDeceleration').setDoubleValue(1200);
behaviorContent.addChild('forwardSpeedMax').setDoubleValue(600);
behaviorContent.addChild('sidewaysAcceleration').setDoubleValue(800);
behaviorContent.addChild('sidewaysDeceleration').setDoubleValue(800);
behaviorContent.addChild('sidewaysSpeedMax').setDoubleValue(400);
behaviorContent.addChild('slopeMaxAngle').setDoubleValue(60);
};

Expand Down
44 changes: 26 additions & 18 deletions Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ namespace gdjs {

_slopeMaxAngle: float;
_slopeClimbingFactor: float = 1;
_forwardAcceleration: float = 1200;
_forwardDeceleration: float = 1200;
_forwardSpeedMax: float = 600;
_gravity: float = 1000;
_maxFallingSpeed: float = 700;
_jumpSpeed: float = 900;
_jumpSustainTime: float = 0.2;
_forwardAcceleration: float;
_forwardDeceleration: float;
_forwardSpeedMax: float;
_gravity: float;
_maxFallingSpeed: float;
_jumpSpeed: float;
_jumpSustainTime: float;

hasPressedForwardKey: boolean = false;
hasPressedBackwardKey: boolean = false;
Expand Down Expand Up @@ -80,6 +80,13 @@ namespace gdjs {

this._slopeMaxAngle = 0;
this.setSlopeMaxAngle(behaviorData.slopeMaxAngle);
this._forwardAcceleration = behaviorData.forwardAcceleration;
this._forwardDeceleration = behaviorData.forwardDeceleration;
this._forwardSpeedMax = behaviorData.forwardSpeedMax;
this._gravity = behaviorData.gravity;
this._maxFallingSpeed = behaviorData.fallingSpeedMax;
this._jumpSpeed = 900; //TODO behaviorData.jumpHeight;
this._jumpSustainTime = behaviorData.jumpSustainTime;
}

private getVec3(x: float, y: float, z: float): Jolt.Vec3 {
Expand Down Expand Up @@ -475,16 +482,18 @@ namespace gdjs {
-Math.abs(forwardSpeed) * this._slopeClimbingFactor,
groundVelocity.GetZ()
);
let stickToFloorStepDownZ = 0;
if (
Math.abs(floorStepDownSpeedZ) <=
this._maxFallingSpeed * worldInvScale
) {
extendedUpdateSettings.mStickToFloorStepDown.Set(
0,
0,
-onePixel + floorStepDownSpeedZ * timeDelta
);
stickToFloorStepDownZ = -onePixel + floorStepDownSpeedZ * timeDelta;
}
extendedUpdateSettings.mStickToFloorStepDown.Set(
0,
0,
stickToFloorStepDownZ
);

this.character.SetRotation(characterBody.GetRotation());
this.character.ExtendedUpdate(
Expand Down Expand Up @@ -567,13 +576,13 @@ namespace gdjs {

this.hasPressedForwardKey = false;
this.hasPressedJumpKey = false;

this._hasReallyMoved =
Math.abs(this.character.GetPosition().GetX() - oldX) >
PhysicsCharacter3DRuntimeBehavior.epsilon ||
PhysicsCharacter3DRuntimeBehavior.epsilon ||
Math.abs(this.character.GetPosition().GetY() - oldY) >
PhysicsCharacter3DRuntimeBehavior.epsilon ||
Math.abs(this.character.GetPosition().GetY() - oldZ) >
PhysicsCharacter3DRuntimeBehavior.epsilon ||
Math.abs(this.character.GetPosition().GetY() - oldZ) >
PhysicsCharacter3DRuntimeBehavior.epsilon;

// console.log('END Step character');
Expand Down Expand Up @@ -852,8 +861,7 @@ namespace gdjs {
*/
isMovingEvenALittle(): boolean {
return (
(this._hasReallyMoved &&
this._currentForwardSpeed !== 0) ||
(this._hasReallyMoved && this._currentForwardSpeed !== 0) ||
this._currentJumpSpeed !== 0 ||
this._currentFallSpeed !== 0
);
Expand Down

0 comments on commit 7be8d2f

Please sign in to comment.