New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Player knockback and add_player_velocity API #8685
Conversation
Will this PR work server or client side ? |
It's client-side, players will have to upgrade. |
4d00a65
to
f30d4ad
Compare
Seems a nice implementation. As far as i can see, this adds a velocity to a punched player, with a direction being the line from puncher to punched, and magnitude determined by damage. After the velocity has been added, the punched player's motion is simply affected by the usual player physics. If i'm right this is exactly what i requested in the previous PR. |
function set_velocity(player, vel)
player:add_velocity(vector.multiply(player:get_velocity(), -1))
player:add_velocity(vel)
end |
|
||
core.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, unused_dir, damage) | ||
if player:get_hp() == 0 then | ||
return -- RIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kicking around dead corpses might be fun or even useful. Do we really want to return here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All movement is ignored when a player is dead, so this wouldn't work anyway.
builtin/game/knockback.lua
Outdated
return -- RIP | ||
end | ||
if damage == 0 or player:get_armor_groups().immortal then | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No knockback for immortal players makes kinda sense (maybe there should be an additional group for no knockback).
The damage == 0
should be moved to core.calculate_knockback
. Someone might want to make a tool that doesn't hurt but pushes.
Maybe the check for the group should be moved to core.calculate_knockback
, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea with immortal
was the same as with zero damage, so it makes sense to move both.
local d = vector.length(dir) | ||
if d ~= 0.0 then | ||
dir = vector.divide(dir, d) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local d = vector.normalize(dir)
does the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need the length of the initial vector afterwards, this saves one vector.length
calculation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, of course.
(Maybe you should return if d is 0.)
62e8895
to
aeca89c
Compare
@@ -4918,6 +4918,15 @@ Misc. | |||
of the creative mode setting, checks for "sneak" to set the `invert_wall` | |||
parameter and `prevent_after_place` set to `true`. | |||
|
|||
* `minetest.calculate_knockback(player, hitter, time_from_last_punch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculate implies that it doesn't modify state. I suggest calling it apply_knockback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it indeed does not modify state
The intended usecase is knockback, but there's potential for more.
Rebased! |
417ef21
to
2b84cfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works.
* Does not apply during free_move. | ||
* Note that since the player speed is normalized at each move step, | ||
increasing e.g. Y velocity beyond what would usually be achieved | ||
(see: physics overrides) will cause existing X/Z velocity to be reduced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that add_player_velocity
cannot be used to knock a player back with speed significantly higher than walk speed? Also how does this interact with anticheat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be in the next stable release? |
This was merged. So I'd hope it would be 👀 |
implements: #2394 #2960
replaces: #5679 #6489
don't squash
To do
This PR is Ready for Review.
Not implemented:
How to test
Punch another player with different kinds of weapons.