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

Ironsights aiming (scripting?)

Started by EoceneMiacid, June 13, 2016, 06:31:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EoceneMiacid

Hi,

I would like to add ironsights capability to my mod.

It's actually pretty easy to achieve, by tweaking the g_gunX, g_guny and g_gunz cvars - but obviously, I would like to add a function that allows me to toggle between the default and tweaked values.

So how do I create this function, and how do I execute it? It's probably a script, I guess?

0x29a



//I dunno how do you realise it on your side
// I just take "zoom" button and see if it's pressed

/* in weapon_base
    void        ADS_IN();
    void        ADS_OUT();
    float buttons;
    boolean isZoomed;
    boolean aimOnce; */

/* In idle
   After while(1){}
*/
buttons = $player1.getButtons();

        if ( buttons == 20 )
        {
            isZoomed = 1;
        }
        if (buttons != 20)
        {
            isZoomed = 0;
        }

        if ( isZoomed && !WEAPON_ATTACK )
        {

            if(!aimOnce)
            {
               
                aimOnce = !aimOnce;
                ADS_IN();
     
            }
  if ( !isZoomed && !WEAPON_ATTACK )
            {
                if(aimOnce)
                {

                    aimOnce = !aimOnce;
                    ADS_OUT();
                }
            }
        }




ADS_IN and OUT are just a functions that do lots and lots of set gunx/y/z in a row
HF && GL

EoceneMiacid

Thanks for your reply, but you're overestimating my familiarity with idTech4 here.

So I need to copy this code into weapon_base.script I copied over from Doom 3?

The Happy Friar

I just modified the models to add the sights & setup the zoom appropriately. 

After firing real guns, if you're firing "at the hip" you're pretty much wasting ammo. You have little idea where the bullets go, it should always be ironsights/scope. 

But it's a game and most players think "aiming" down the gun makes it more accurate vs YOU more accurate.  :)

But yeah, I modified the models & adjusted the zoom per weapon.

EoceneMiacid

Okay, and how does that info help me getting iron sights into the game? :p

In the meantime, I've cobbled together this simple hack:

bind "MOUSE2" "toggle g_guny 0 4;toggle g_gunx 0 -3"




0x29a

Nasty hack, indeed.
Code I've posted goes to the script of the weapon you want to mod. For more info, download my mod (Overthinked) and look at script files. Dedicated ADS_IN/OUT methods give you nice continuity if you don't have proper animations for iron sights.

The Happy Friar

Quote from: EoceneMiacid on June 13, 2016, 11:24:33 AM
Okay, and how does that info help me getting iron sights into the game? :p

Just modify the model/texture so you have iron sights on the models & adjust the zoom in values for each weapon. 

Looking at the stock models in game, the pistol needs a rear sight, shotgun should have it's narrowed (or have an open sight added), machinegun needs a front & rear one, plasma needs a rear one (the ammo counter could have one ontop), RL needs to be hollowed out like the plasma.

The RL should be the easiest, it's just modifying the texture/material so it's transparent on the proper areas.  For the pistol, machinegun & plasma wouldn't need any changes to the model, just a new sight model added on top of it would do the trick.  The new model would be bound to the same bone as the weapon body, that makes it even easier. 

EoceneMiacid

Quote from: The Happy Friar on June 13, 2016, 12:40:24 PM
Quote from: EoceneMiacid on June 13, 2016, 11:24:33 AM
Okay, and how does that info help me getting iron sights into the game? :p

Just modify the model/texture so you have iron sights on the models & adjust the zoom in values for each weapon. 

Looking at the stock models in game, the pistol needs a rear sight, shotgun should have it's narrowed (or have an open sight added), machinegun needs a front & rear one, plasma needs a rear one (the ammo counter could have one ontop), RL needs to be hollowed out like the plasma.

The RL should be the easiest, it's just modifying the texture/material so it's transparent on the proper areas.  For the pistol, machinegun & plasma wouldn't need any changes to the model, just a new sight model added on top of it would do the trick.  The new model would be bound to the same bone as the weapon body, that makes it even easier.

Um... ok :p

I just barely managed to understood what all that means. Please understand, I'm nowhere near experienced enough with the engine to do all this and there's a distinct lack of thorough documentation out there.

VGames

Then stop trying to do such advanced things. Start small and learn the layout. Specialize in something. Plenty of mods to borrow assets from. You're moving to fast.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

EoceneMiacid

Quote from: VGames on June 13, 2016, 09:03:08 PM
Then stop trying to do such advanced things. Start small and learn the layout. Specialize in something. Plenty of mods to borrow assets from. You're moving to fast.

That's probably true, but I'm already quite pleased with where I stand given the time I've had learning the tech.




oneofthe8devilz

#10
I think this mechanic is what you might be looking for...



It's been a while since I have implemented ironsights to MCS, but if I remember correctly no significant C++ code was involved. So you could take a look at how it was implemented by inspecting the MCS asset files (defs,models,animations and scripts) and then accordingly apply your own solution to your own idtech4 project.
I got six little friends and they all run faster than you ;)


Check out our mods at
moddb or the SPS Homepage