Hi again! So Im currently trying to figure out how to add knockback to my game, but I’m stuck I searched around a bit, but the only thing I could find was this:
public void knockback(float r, float force){
r = r - 180;
force *= knockbackResistance; // how heavy the entity is (so lesser knock back)
knockbackTimer = force * 8;
knockbackTo = new Vector2((force * (float) MathUtils.sin(r * MathUtils.degreesToRadians)),
(-force * (float) MathUtils.cos(r * MathUtils.degreesToRadians)))
.add(position);
}
//Then I have this on the update loop for the entity
public void update(){
if(knockbackTimer > 0){
position = Tools.lerp(position, knockbackTo, 0.2f);
knockbackTimer -= Gdx.graphics.getDeltaTime() * 1000;
}
}
To be honest, I really don’t understand it Help, please?