Skip to content
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

Merged
merged 2 commits into from Aug 10, 2019
Merged

Conversation

sfan5
Copy link
Member

@sfan5 sfan5 commented Jul 16, 2019

implements: #2394 #2960
replaces: #5679 #6489
don't squash

To do

This PR is Ready for Review.

Not implemented:

  • suggestion from Knockback #5679 (comment) to use tool/armor groups to determine knockback
  • knockback for entities (possibly doable using interpolated move)

How to test

Punch another player with different kinds of weapons.

@appgurueu
Copy link
Contributor

appgurueu commented Jul 17, 2019

Will this PR work server or client side ?
Do players have to upgrade in order to use it ? I guess yes ?

@sfan5
Copy link
Member Author

sfan5 commented Jul 17, 2019

It's client-side, players will have to upgrade.

src/content_sao.h Outdated Show resolved Hide resolved
@sfan5 sfan5 force-pushed the knockback branch 2 times, most recently from 4d00a65 to f30d4ad Compare July 17, 2019 21:44
@paramat
Copy link
Contributor

paramat commented Jul 17, 2019

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.

@LoneWolfHT
Copy link
Contributor

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
Copy link
Member

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?

Copy link
Member Author

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.

return -- RIP
end
if damage == 0 or player:get_armor_groups().immortal then
return
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.)

src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
@sfan5 sfan5 force-pushed the knockback branch 2 times, most recently from 62e8895 to aeca89c Compare July 23, 2019 23:21
@@ -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,
Copy link
Member

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

Copy link
Member Author

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

builtin/game/knockback.lua Outdated Show resolved Hide resolved
The intended usecase is knockback, but there's potential for more.
@sfan5
Copy link
Member Author

sfan5 commented Aug 8, 2019

Rebased!

@sfan5 sfan5 force-pushed the knockback branch 2 times, most recently from 417ef21 to 2b84cfc Compare August 10, 2019 16:58
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works.

@sfan5 sfan5 merged commit 291e773 into minetest:master Aug 10, 2019
@sfan5 sfan5 deleted the knockback branch August 10, 2019 17:44
* 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.
Copy link
Contributor

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?

Copy link
Member Author

@sfan5 sfan5 Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean [...]

Yes, see #8796

Also how does this interact with anticheat?

It works.

@Extex101
Copy link

Will this be in the next stable release?
And when Is the next stable release?

@LoneWolfHT
Copy link
Contributor

LoneWolfHT commented Sep 14, 2019

This was merged. So I'd hope it would be 👀
IIRC there will be a MT stable release before the end of the year. Make sure you test out all the release candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet