[Mod]Player knockback[punchback]

User avatar
LMD
Member
 
Posts: 721
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

[Mod]Player knockback[punchback]

by LMD » Wed Jun 20, 2018 17:06

Player knockback
This (small) mod adds player knockback. Written for Magic-CTF by LMD. It does not use mover entities for several reasons, but instead player:move_to. The main task of this mod is to use player:move_to properly and not to move players into solid blocks. If there are errors, please let me know on GitHub.

API :
There are 6 global variables concerning punchback which can be modified from other mods. How they work can be seen in the commented source.

License : GPLv3

Depends : None

Download/Source(GitHub) : https://github.com/appgurueu/punchback

Code:
Code: Select all
PUNCHBACK_STEPS=5 --Punchback simulation accuracy
DEFAULT_PUNCHBACK=0.2 --Default punchback strenght in blocks - used when tool hasnt got punchback capability
PUNCHBACK_RELOAD=1 --Punchback=factor*tool punchback*time from last punch, reload is factor
PUNCHBACK_MAX=3 --beyond 3 s time from last punch there's no difference
PLAYER_SIZE=0.6 --Player collisionbox simulation size in percent, eg 0.6 means 60 percent of real size

local factor=1

minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
    local orig=vector.multiply(hitter:get_look_dir(),(pcall(tool_capabilities.punchback) or DEFAULT_PUNCHBACK) * math.min(PUNCHBACK_RELOAD*time_from_last_punch,PUNCHBACK_MAX)) --Calc punchback vector * strength
    local mult=vector.divide(vector.normalize(orig),PUNCHBACK_STEPS) --Divide by steps
    local pos=player:get_pos() --Player pos
    for i=0,math.ceil(vector.length(orig)*PUNCHBACK_STEPS) do --Simulation
        local d=PLAYER_SIZE
        for _,y in pairs({-1*d,0,1*d}) do
            for _,x in pairs({-0.5*d,0,0.5*d}) do
                for _,z in pairs({-0.5*d,0,0.5*d}) do
                    local v=vector.add(vector.add(pos,{x=x,y=y,z=z}),mult)
                    local floor={x=math.floor(v.x*factor+0.5)/factor,y=math.floor(v.y*factor+0.5)/factor,z=math.floor(v.z*factor+0.5)/factor}
                    if not (minetest.get_node(floor).walkable==true) then --Stop moving when colliding with solid node
                        goto overjump
                    end
                end
            end
        end
        pos=vector.add(pos,mult)
    end
    ::overjump::
    player:moveto(pos) --Actual punchback
end)
Last edited by LMD on Thu Nov 08, 2018 19:56, edited 3 times in total.
Magic-CTF(soon)MTPCFractal-SuiteModel Creator Schematic CreatorColorfulXmas BallsWebsite • Never judge me by my age
 

User avatar
Stix
Member
 
Posts: 1357
Joined: Fri Aug 04, 2017 14:19
Location: USA
IRC: nil
In-game: Stix [+alts]

Re: [MOD][API][TINY][SERVER][PVP]Player punchback[punchback]

by Stix » Wed Jun 20, 2018 18:50

First of all it should be called "knockback" not "punchback", and second a demonstration video would be nice :P.
Hey, what can i say? I'm the bad guy.
Next release of your favorite game? "Bugfixes" --Wuzzy
[OLD]The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

entuland
Member
 
Posts: 117
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][PVP]Player punchback[punchback]

by entuland » Fri Jun 22, 2018 10:43

Stix wrote:First of all it should be called "knockback" not "punchback", and second a demonstration video would be nice :P.

Yep, a "punchback" mod should be one where you puch a node and the node punches back at you :P

LMD: nice mod in any case, improves fighting mechanics nicely :)
 

User avatar
LMD
Member
 
Posts: 721
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by LMD » Fri Jun 22, 2018 11:01

thanks :) does it work properly ? didn't test it that much...
Magic-CTF(soon)MTPCFractal-SuiteModel Creator Schematic CreatorColorfulXmas BallsWebsite • Never judge me by my age
 

entuland
Member
 
Posts: 117
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by entuland » Fri Jun 22, 2018 11:41

LMD wrote:thanks :) does it work properly ? didn't test it that much...

ehehehe, you just asked for this mod to be moved to the released mods section of the forum and you didn't extensively test it?
 

User avatar
LMD
Member
 
Posts: 721
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by LMD » Fri Jun 22, 2018 12:56

well, extensive testing would require multiplayer ? and i havent got that many people around me whose time i can waste.
Magic-CTF(soon)MTPCFractal-SuiteModel Creator Schematic CreatorColorfulXmas BallsWebsite • Never judge me by my age
 

entuland
Member
 
Posts: 117
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by entuland » Fri Jun 22, 2018 13:38

LMD wrote:well, extensive testing would require multiplayer ? and i havent got that many people around me whose time i can waste.

Not a multiplayer myself, but I guess you would need to test it on a live server, considering the scope of your mod.

You could still run multiple instances of MT locally and connect to the same server to test it on your own without wasting anyone else's time. Just punch one of your alter-egos running on a different instance and test everything out.
 

User avatar
Joseph13
Member
 
Posts: 265
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph

Re: [Mod]Player knockback[punchback]

by Joseph13 » Thu May 16, 2019 00:40

is this mod still being worked on or maintained?
Testin' mines since 1989
 

User avatar
LMD
Member
 
Posts: 721
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

Re: [Mod]Player knockback[punchback]

by LMD » Thu May 16, 2019 15:14

Probably not. I will eventually decide to do an upgrade for 5.0
Magic-CTF(soon)MTPCFractal-SuiteModel Creator Schematic CreatorColorfulXmas BallsWebsite • Never judge me by my age
 

User avatar
Joseph13
Member
 
Posts: 265
Joined: Tue Dec 06, 2016 05:35
In-game: Joseph

Re: [Mod]Player knockback[punchback]

by Joseph13 » Thu May 16, 2019 16:41

I installed it, but when I hit a player no knockback occurs. Whats the deal banana peel?
Testin' mines since 1989
 


Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 6 guests