I am building a rocket simulator and decided to start off with the physics of it (obviously). so I made a script so when i press shift the throttle should go up by 1/100 of the max throttle. I launched it and it doesn’t say theres an issue, but it doesnt work. If anyone can help here is project link and the script I made:
https://playcanvas.com/editor/scene/1791198
var Fly = pc.createScript(‘fly’);
Fly.attributes.add(‘engineLimiter’, {
type: ‘number’,
default: 120,
title: ‘Engine Limiter’,
description: ‘The max thrust of the rocket’,
});
// initialize code called once per entity
Fly.prototype.initialize = function() {
this.currentThrust = 0;
this.thrustBackup = this.currentThrust;
this.raiseFactor = this.engineLimiter / 100;
};
// update code called every frame
Fly.prototype.update = function(dt) {
//raise thrust
if (this.app.keyboard.isPressed(pc.KEY_SHIFT)) {
if (this.currentThrust = this.engineLimiter === false ) {
this.currentThrust = this.thrustBackup + this.raiseFactor;
this.thrustBackup = this.currentThrust;
}
}
// cut the thrust
if (this.app.keyboard.isPressed(pc.KEY_X)) {
this.currentThrust = 0;
this.thrustBackup = this.currentThrust;
}
//Apply the force
this.entity.rigidbody.applyForce(0,this.currentThrust,0);