- Joined
- Jan 20, 2021
- Messages
- 4
- Reaction score
- 0
- First Language
- English
- Primarily Uses
- RMMZ
Hello! I've been trying to get enemies to shake when you hit them in battle. With TheoAllen's blessing I was able to modify a plugin he wrote for screenshake to do just that.
The problem is that ALL enemies shake when you hit them, and they even shake when they hit you!
Can someone help me figure out how to make it so only the enemy who was hit, shakes?
The problem is that ALL enemies shake when you hit them, and they even shake when they hit you!
Can someone help me figure out how to make it so only the enemy who was hit, shakes?
JavaScript:
var Theo = Theo || {}
Theo.Shake = {}
Theo.Shake.gameTemp_init = Game_Temp.prototype.initialize;
Game_Temp.prototype.initialize = function(){
Theo.Shake.gameTemp_init.call(this);
this.shake_maxdur = 0;
this.shake_dur = 0;
this.shake_pow = 0;
}
Game_Temp.prototype.shake_screen = function(power, duration){
this.shake_maxdur = duration;
this.shake_dur = duration;
this.shake_pow = power;
}
Theo.Shake.spritesetEnemy_updatePos = Sprite_Enemy.prototype.updatePosition;
Sprite_Enemy.prototype.updatePosition = function(){
Theo.Shake.spritesetEnemy_updatePos.call(this);
if($gameTemp.shake_dur > 0){
$gameTemp.shake_dur -= 1;
let rate = $gameTemp.shake_dur/$gameTemp.shake_maxdur;
this.x += Math.random() * $gameTemp.shake_pow * rate * (Math.random() >= 0.5 ? 1 : -1);
this.y += Math.random() * $gameTemp.shake_pow * rate * (Math.random() >= 0.5 ? 1 : -1);
}
}
Sprite_Battler.prototype.setupDamagePopup = function() {
if (this._battler.isDamagePopupRequested()) {
if (this._battler.isSpriteVisible()) {
this.createDamageSprite();
$gameTemp.shake_screen(10, 45);
}
this._battler.clearDamagePopup();
this._battler.clearResult();
}
};