Godot Version
4.3
Question
I’ve been trying to recreate the [shake] effect that is built into Godot, and I’ve successfully made it shake, just not in the same way as the one built into Godot.
The version I’ve made shakes way too fast and I have no clue how to change the speed to match Godot’s one.
This is what I’ve made so far:
private string bbcode = "advshake";
private float _letter = 0.0f;
private TextServer GetTextServer()
{
return TextServerManager.GetPrimaryInterface();
}
public float RollRandom()
{
return GD.RandRange(-1, 1);
}
public override bool _ProcessCustomFX(CharFXTransform charFX)
{
var character = GetTextServer().FontGetCharFromGlyphIndex(charFX.Font, 1, charFX.GlyphIndex);
var freq = (float)charFX.Env.GetValueOrDefault("freq", 0.1f);
var baseIntensity = (float)charFX.Env.GetValueOrDefault("intensity", 10f);
var time = (float)charFX.Env.GetValueOrDefault("time", 0.0f);
Vector2 newRandomPos = new Vector2(RollRandom() * baseIntensity, RollRandom()) * baseIntensity;
var previousPos = charFX.Offset;
var offset = new Vector2(
Mathf.Lerp(previousPos.X, newRandomPos.X, freq),
Mathf.Lerp(previousPos.Y, newRandomPos.Y, freq)
);
charFX.Offset = offset;
return time == 0 || charFX.ElapsedTime < time;
}
}
Godot’s one updates more slowly it seems like. I have no clue.