toomuchzelda
Active member
- Joined
- May 30, 2020
- Messages
- 59
tl;dr: a bunch of adjustments to lib's RWF to make the combat feel better and closer to 1.8. Comparison video at the bottom.
This post is about replicating 1.8 combat in SnD. I'll go over some issues present in Red Warfare/Athios PvP system, and how I went about fixing them. This is in the hopes that, should Athios want their server to closer mimic the combat of pre-1.9, they will find this useful. I'll be referencing libraryaddict's Red Warfare source code, which you can find here: https://github.com/libraryaddict/RedWarfare
It all started 46 years ago. I came into this world weighing 3.5 kilograms, at 12.45pm on the 24th of November, 1975. My mother was
ha ha.
Knockback
Knockback has had a bad history on Red Warfare. libraryaddict tried to make '1.8 like' knockback on his server Red Warfare 2 (which was 1.10.2 at the time) but didn't succeed. General consensus was that it was too weak and just wasn't 1.8. Athios had this problem too a little more recently. There was lots of hit trading and little combo-ing. Martoph has improved it and most people seem to think it's good but the more competitive (sweaty) players think there is still room to improve. I looked into why libraryaddict's knockback was poor:
The main knockback calculating happens in me.libraryaddict.core.damage.CustomDamageEvent.recalculateKnockback().
libraryaddict's code:
Generalised, the steps go like this (In the event that one entity has attacked another):
1. Get the difference in X and Z of damager/damagee (attacker/victim)
2. Ignoring height, find distance between damager/damagee
3. Get the current velocity of the victim and half it
4. Calculate a knockback vector with negative of normalised X and Z components multiplied by 0.4. Y is just 0.4. And add it to their halved movement vector. This finishes calculating a regular attack/punch/whatever
5. If the player has knockback on their sword, or is sprinting, or has some other knockback multipliers then add 0.1 to Y of the previous vector, and negative of normalised X Z multiplied by the number of knockback levels divided by 2. (Sprinting also counts as 1 knockback level).
6. Done
There are a few extra steps outside of this method but they aren't significant, at least for melee attacks.
I would post 1.8 vanilla code to compare but I believe that's copyrighted and not allowed to be distributed. Anyway, lib's method here is actually extremely similar to vanilla 1.8, there are just a couple of differences: After step 4, make sure the Y value isn't higher than 0.4 (0.4000000059604645 to be exact), and when applying knockback multipliers, use the attacker's horizontal looking direction (yaw) instead of the difference in attacker/victim locations.
Adjusted to match 1.8 it looks something like this:
Putting this into a 1.16.5 plugin, it's identical to 1.8. The distance pushed as well as the overall feel. But it's still different in snd for some reason?
It turns out that in another part of Red Warfare's code libraryaddict included a function to reduce or otherwise adjust velocity sent to the players by the server, including knockback velocity. It acts as a sort of filter for all velocity information sent to players.
Continued...
This post is about replicating 1.8 combat in SnD. I'll go over some issues present in Red Warfare/Athios PvP system, and how I went about fixing them. This is in the hopes that, should Athios want their server to closer mimic the combat of pre-1.9, they will find this useful. I'll be referencing libraryaddict's Red Warfare source code, which you can find here: https://github.com/libraryaddict/RedWarfare
It all started 46 years ago. I came into this world weighing 3.5 kilograms, at 12.45pm on the 24th of November, 1975. My mother was
ha ha.
Knockback
Knockback has had a bad history on Red Warfare. libraryaddict tried to make '1.8 like' knockback on his server Red Warfare 2 (which was 1.10.2 at the time) but didn't succeed. General consensus was that it was too weak and just wasn't 1.8. Athios had this problem too a little more recently. There was lots of hit trading and little combo-ing. Martoph has improved it and most people seem to think it's good but the more competitive (sweaty) players think there is still room to improve. I looked into why libraryaddict's knockback was poor:
The main knockback calculating happens in me.libraryaddict.core.damage.CustomDamageEvent.recalculateKnockback().
libraryaddict's code:
Java:
private Vector recalculateKnockback()
{
Vector toReturn = _knockback.clone();
if (getDamager() != null)
{
Vector offset = getDamager().getLocation().toVector().subtract(getDamagee().getLocation().toVector());
double xDist = offset.getX();
double zDist = offset.getZ();
while (!Double.isFinite(xDist * xDist + zDist * zDist) || xDist * xDist + zDist * zDist < 0.0001)
{
xDist = UtilMath.rr(-0.01, 0.01);
zDist = UtilMath.rr(-0.01, 0.01);
}
double dist = Math.sqrt(xDist * xDist + zDist * zDist);
if (_calculateKB)
{
Vector vec = getDamagee().getVelocity();
vec.setX(vec.getX() / 2);
vec.setY(vec.getY() / 2);
vec.setZ(vec.getZ() / 2);
vec.add(new Vector(-(xDist / dist * 0.4), 0.4, -(zDist / dist * 0.4)));
toReturn.add(vec);
}
double level = 0;
for (int value : _knockbackMult.values())
{
level += value;
}
if (level != 0)
{
level /= 2;
toReturn.add(new Vector(-(xDist / dist * level), 0.1, -(zDist / dist * level)));
}
}
return toReturn;
}
1. Get the difference in X and Z of damager/damagee (attacker/victim)
2. Ignoring height, find distance between damager/damagee
3. Get the current velocity of the victim and half it
4. Calculate a knockback vector with negative of normalised X and Z components multiplied by 0.4. Y is just 0.4. And add it to their halved movement vector. This finishes calculating a regular attack/punch/whatever
5. If the player has knockback on their sword, or is sprinting, or has some other knockback multipliers then add 0.1 to Y of the previous vector, and negative of normalised X Z multiplied by the number of knockback levels divided by 2. (Sprinting also counts as 1 knockback level).
6. Done
There are a few extra steps outside of this method but they aren't significant, at least for melee attacks.
I would post 1.8 vanilla code to compare but I believe that's copyrighted and not allowed to be distributed. Anyway, lib's method here is actually extremely similar to vanilla 1.8, there are just a couple of differences: After step 4, make sure the Y value isn't higher than 0.4 (0.4000000059604645 to be exact), and when applying knockback multipliers, use the attacker's horizontal looking direction (yaw) instead of the difference in attacker/victim locations.
Adjusted to match 1.8 it looks something like this:
Java:
private Vector recalculateKnockback()
{
Vector toReturn = _knockback.clone();
if (getDamager() != null)
{
Vector offset = getDamager().getLocation().toVector().subtract(getDamagee().getLocation().toVector());
double xDist = offset.getX();
double zDist = offset.getZ();
while (!Double.isFinite(xDist * xDist + zDist * zDist) || xDist * xDist + zDist * zDist < 0.0001)
{
xDist = UtilMath.rr(-0.01, 0.01);
zDist = UtilMath.rr(-0.01, 0.01);
}
double dist = Math.sqrt(xDist * xDist + zDist * zDist);
if (_calculateKB)
{
Vector vec = getDamagee().getVelocity();
vec.setX(vec.getX() / 2);
vec.setY(vec.getY() / 2);
vec.setZ(vec.getZ() / 2);
vec.add(new Vector(-(xDist / dist * 0.4), 0.4, -(zDist / dist * 0.4)));
if(vec.getY() > 0.4) //cap Y value
vec.setY(0.4);
toReturn.add(vec);
}
double level = 0;
for (int value : _knockbackMult.values())
{
level += value;
}
if (level != 0)
{
level /= 2;
float yaw = getDamager().getLocation().getYaw();
Vector kbEnch;
double xKb = (double) -Math.sin(yaw * 3.1415927F / 180.0f) * (float) level;
double zKb = (double) Math.cos(yaw * 3.1415927F / 180.0f) * (float) level;
kbEnch = new Vector(xKb, 0.1d, zKb);
toReturn.add(kbEnch);
}
}
return toReturn;
}
It turns out that in another part of Red Warfare's code libraryaddict included a function to reduce or otherwise adjust velocity sent to the players by the server, including knockback velocity. It acts as a sort of filter for all velocity information sent to players.
Continued...
Last edited: