News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Melee push-back

Started by 0x29a, June 07, 2016, 08:02:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0x29a

Hi there, everyone!

How can I add push-back value to the melee attack? (for example to fists)
I tried adding knockback and push values ( even huge ones ) in the def file, but nothing happens. That is - happens - bacause damage is applied correctly, but no push-back at all... I'd like melee attacks to behave like shotgun bullets - you know - to get enemy further away from the player.

Thanks in advance !

The Happy Friar

Maybe they don't work for melee.  I'd have to check the code to see.  At worst, you have an invisible projectile with a short distance that does the same thing.

0x29a

I've added the projectile (also Vgames recommended that solution) but, unfortunately, somehow it does not work... And I've even copied entitydef for other projectile that does work - still no joy...
You guys have any example def/script files in which that concept was realised?
Also, thanks for quick reply!

0x29a

Edit - all right! I got it working!

Thankfully in my SDK I can switch between projectile types on the fly

VGames

Care to share that snippet of code?
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

EoceneMiacid

I thought you were fundamentally opposed to sharing? :p

VGames

Quote from: EoceneMiacid on June 07, 2016, 05:06:43 PM
I thought you were fundamentally opposed to sharing? :p

I'm releasing my source very soon. Why would I be opposed?
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

0x29a

#7
@VGames:
Of course, just download my whole SDK from moddb and search for relevant code lines. It's in Weapon.cpp, in method idWeapon::Event_LaunchProjectiles

It's a bit too long to post it here, but I think I'll manage to put relevant parts:
First of all, let's change definition in Weapon.h:

   void                    Event_LaunchProjectiles( int num_projectiles, float spread, float fuseOffset, float launchPower, float dmgPower , int melee);

And in Weapon.cpp:

void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float fuseOffset, float launchPower, float dmgPower,int melee)


We're doing this because otherwise melee attacks will either use ammo, or we'd need to disable ammo usage altogether. Either option is not feasible, so we're doing our own solution. Not very nice and against practices of modern software engineering, but it does the job, so...

Let's insert our boolean checkup in relevant places in Weapon.cpp :


// Code...
    if ( clipSize && ammoRequired && (melee <= 0) ) {
            ammoClip -= powerAmmo ? dmgPower : ammoRequired;
        }
// Code...
  if(melee <= 0)
    {
        renderEntity.shaderParms[ SHADERPARM_DIVERSITY ]    = gameLocal.random.CRandomFloat();
        renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ]   = -MS2SEC( gameLocal.realClientTime );
    }
// This one is actually required, otherwise game crashes with segfault
// Code...
if( tracer && (melee <= 0) ) {
//just in case
}
//Code...
if ( !lightOn && (melee <= 0)  ) {
        MuzzleFlashLight(); //This prevents gun from flashing when doing melee attack.
    }
   if( melee <= 0 )
    {

        owner->WeaponFireFeedback( &weaponDef->dict );

        // reset muzzle smoke
        weaponSmokeStartTime = gameLocal.realClientTime;
    }

//Code...



That about wraps it up. Last thing to do is to modify doom_events.script, so it looks like this:


scriptEvent void    launchProjectiles( float num_projectiles, float spread, float fuseOffset, float launchPower, float dmgPower , float melee);


Now onto the boring part... We need to add "0" to every single launchProjectiles call arguments list in every script where actual projectiles are being fired. Go for Vim with easymotion plugin or you'll die of boredom after first two files.

So, now that we have our infrastructure ready, let's actually use it. We'll take example of pistol weapon:



entityDef weapon_pistol {

// Code...
        "def_projectile"            "projectile_bullet_pistol"
        "def_projectile2"           "projectile_melee"
        "ammoType"                  "ammo_bullets"
        "snd_whoosh"                "fist_whoosh"
// Code...
}

//More code...

entityDef projectile_melee_damage {
       
        "damage"            "15"
        "kickDir"           "1 1 1"

        "mtr_blob"          "genericDamage"
        "blob_time"         "300"
        "blob_size"         "400"
        "blob_offset_x"     "400"

        "knockback"         "450"  // 6, 5, 8 last time
        "push"              "300"

        "gib"               "0"

        "kick_time"             "400"
        "kick_amplitude"        "2"

        "dv_time"               "100"

        //---------------------------------------------
        //  Material based Sound Feedback
        //---------------------------------------------

        "snd_tracer"                "bullet_flight"
        "snd_flesh"                 "bullet_impact_flesh"
        "snd_plastic"               "bullet_impact_plastic"
        "snd_cardboard"             "bullet_impact_cardboard"
        "snd_metal"                 "bullet_impact_metal" // Also is a default sound
        "snd_stone"                 "bullet_impact_stone"
        "snd_wood"                  "bullet_impact_wood"
        "snd_glass"                 "bullet_impact_glass"
        "snd_liquid"                "bullet_impact_liquid"
        "snd_surftype10"            "bullet_impact_concrete"
        "snd_surftype11"            "bullet_impact_sand"


        //----------------------------------------------
        "smoke_wound_flesh" "burstysquirt.prt"
        "mtr_wound_flesh"   "textures/decals/hurt02"
        "mtr_wound_metal"   "textures/decals/chainsawh02"
        "mtr_wound_glass"   "textures/decals/chainsawh02"
}
//All values fairly orientational. Works pretty damn good for me. Also, material definitions may vary drastically between mods, so double check those.


entityDef projectile_melee {
    "spawnclass"                "idProjectile"
        "mins"                      "-3 -3 -3"
        "maxs"                      "3 3 3"
        "cone"                      "10"
        "scale"                     "1"
        "noshadows"                 "1"

        "tracers"                   "0" //If this flag and launchFromBarrel flag are set to 1, the new tracer logic is enabled

        "def_damage"                "projectile_melee_damage"

        "launchFromBarrel"          "1"
        "health"                    "0"
        "velocity"                  "350 300 300" // We want the invisible projectile to be launched on certain angle, as the floor will stop monster from backing up
        "angular_velocity"          "0 0 0"
        "thrust"                    "0"
        "thrust_start"              "0"
        "thrust_end"                "0"
        "linear_friction"           "0"
        "angular_friction"          "0"
        "contact_friction"          "0"
        "bounce"                    "0.6"
        "mass"                      "75" // Good enough. Marine is a sportsman.
        "gravity"                   "0"
        "fuse"                      "0.1"// Theoretically you can set "fuse" to "0" in both DentonMod and FusionSDK, and then projectile velocity becomes it's range.
//This, however, didn't really worked for me, so I'm terminating projectile after 0.1 of a second. Looks pretty realistic
//and it's quite easy to land a well placed whack in a head.

       


Finally, we need to add Melee method to weapon_pistol.script :



object weapon_pistol : weapon_base {
//Code...
float projType;
  void        Melee();
};

void weapon_pistol::Melee() {
    projType = 1;
    changeProjectileDef( projType);
    if(ammoInClip())
    {
        playAnim( ANIMCHANNEL_ALL,"melee" ); //Pistol looks different when out of ammo.
//And my SDK does not disable the weapon when the ammo is gone.
    }else{
        playAnim( ANIMCHANNEL_ALL,"melee_empty" ); // So we need two custom anims instead of one.
    }
    startSound( "snd_whoosh", SND_CHANNEL_ITEM, true );
    launchProjectiles( 1, 0.1, 0, 1.0, 1.0,1 );
    waitUntil( animDone( ANIMCHANNEL_ALL, 0 ) );
    projType = 0;
    changeProjectileDef( projType);
    sys.wait(0.1); //Let's wait a bit in case melee button is still pressed.
    weaponState( "Idle", 0 );
}




And that's it, lots of joy.
I'll release my SDK with this hack right after VGames will release his, because I'd like to incorporate improved gibbing in my mod too.

Cheers!

Edit: I believe I forgot that changeProjectileDef methods must be added everywhere, too, in both SDK and doom_events.script. It's kinda obvious, but I'd rather include this remark anyway, so in advance sorry for being redundant. 

VGames

No I don't need any of that. I got working melee attacks already. You know that. I though you said u had a way to set up a projectile to push enemies around properly. Because sometimes they push and sometimes they don't push the monsters as they should.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

0x29a

Ah, okay then -
thing is to launch projectile a little bit upwards. In this way, with enough mass/push values, monster will get up from the floor for a moment and projectile will push him away.

VGames

Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

0x29a

no problemo. Maybe someone will find that piece of code useful, so let's just leave it here ;)