Page 1 of 7 12345 ... LastLast
Results 1 to 10 of 69

Thread: Quick and fun projectile path tracing!

  1. #1

    Quick and fun projectile path tracing!

    This is a fairly simple script I began writing to after being a bit curious about how ARMA's bullet physics worked, particularly the ricocheting. Recently there was a post on /r/ARMA about bullet penetration, so I cleaned it a bit up to get what you see below. This'll basically trace the movements of projectiles, so you can very clearly see their flight path, arc, and interaction with cover. It's not perfect, but it does what it needs to pretty well. Plus it's surprisingly addicting to just run around and shoot stuff just to see what happens to the bullets.

    UPDATE 10/26/2013:
    As some of you may have seen, Dslyecxi recently made a video that featured a modified version of this script, where the color of the line was reflective of the velocity of the bullet at that moment. He posted his modifications, which are now implemented in the main script! To activate it, pass true as the seventh parameter, like so:

    PHP Code:
    [playernilnilnilnilniltruecall hyp_fnc_traceFire
    Note that as it stands, enabling the velocity-based coloring will override whatever color you specify in the second parameter. I have an idea or two of ways to fix it, but wanted to get this update out there first.

    Also, I completely forgot that the Steam Workshop was a thing, so I published a very simple mission with this script, and Tonic's Virtual Ammobox System and Virtual Vehicle Spawner enabled here:
    http://steamcommunity.com/sharedfile.../?id=189421090

    If there are any problems with the Steam Workshop mission, please mention them to me, as I very rarely actually publish missions, just scripts.

    The code:

    Download the raw code: https://raw.github.com/hypnomatic/AR...cer_v0-2-1.sqf

    Link to Steam Workshop page for a simple mission featuring this script: http://steamcommunity.com/sharedfile.../?id=189421090

    How to use:

    For basic use on just yourself, assuming you don't want to deal use the Steam Workshop mission, all you need to do is create a new mission, and paste the linked code into your init.sqf. After all that code in your init.sqf, add the line:

    PHP Code:
     [] call hyp_fnc_traceFire
    Save the file, restart your mission, and you should be good to go! With no extra parameters, this code is functionally equivalent to the original: it creates red lines behind projectiles fired by the player that are super smooth and persist forever. You can specify more parameters within the square brackets if you want a more specific outcome, as in the following examples.

    PHP Code:
     [] call hyp_fnc_traceFire
    Save the file, restart your mission, and you should be good to go! With no extra parameters, this code is functionally equivalent to the original: it creates red lines behind projectiles fired by the player that are super smooth and persist forever. You can specify more parameters within the square brackets if you want a more specific outcome, as in the following examples.

    The syntax and expected parameters are as follows: (Note that all 7 parameters have default values, so you don't need to specify all of them if you don't want that specific feature.)

    PHP Code:
    [_unit_color_lifetime_interval_maxDistance_maxDurationtrackVelcall hyp_fnc_traceFire
    • 0: _unit - Unit or vehicle to trace the projectiles of. Defaults to the player if no other parameter is specified.
    • 1: _color - Color array for all lines fired by this unit. This is an array formatted as [r,g,b,a], with each value being between 0 and 1. (BIS wiki page)
    • 2: _lifetime - Maximum number of seconds the projectile's line should linger after firing. Note that this timer starts at the same time as maxDuration, but is not checked until after the script finishes drawing a line. This can be thought of as a lower bound for how long a line will exist, as all lines will persist AT LEAST for lifetime's duration.
    • 3: _interval - Number of frames to skip between each adding segment of the line. Defaults to skipping no frames, so the lines are updated every frame.
    • 4: _maxDistance - Maximum distance from the initial position a projectile's line should be updated. Defaults to no maximum.
    • 5: _maxDuration - Maximum number of seconds from firing a projectile's line should be updated. Defaults to no maximum.
    • 6: _trackVel: If true, _color is overridden by the a color indicative of velocity at that moment. Thanks to Dslyecxi for this one! (Default false)


    All of these options may be a bit confusing, so let me offer an example or two:
    PHP Code:
    [player, [1,0,0,1], 32nil3call hyp_fnc_traceFire
    Can be thought of as saying:
    Track every projectile of:
    the player,
    with a red line,
    that will last for at least 3 seconds,
    that is updated every third frame (ie 2 frames skipped between each update),
    with no limit on distance,
    but will not be updated for more than 2 seconds.

    Now, if you want to completely omit a parameter so the default value is used, you have two options. You can either pass nil in place of that parameter, as in the example, which is ARMA's equivalent of "nothing". If you only want to pass specify a unit, and use the defaults for everything else, simply omitting all unwanted parameters like so:
    PHP Code:
    [playercall hyp_fnc_traceFire
    However note that this only works if you want to leave out all parameters after the ones you specify. So if I wanted to specify a player and a max duration, I would need to pass:
    PHP Code:
    [playernilnilnilnil5call hyp_fnc_traceFire
    If you don't really mess with scripts much, this may be a bit tough to wrap your head around, so I'll be happy to answer any questions you may have.

    To get a bit more fancy, you can create a few units/vehicles in the editor, name them, and follow the example near the top of this post to specify your own parameters! Just put whatever you named your unit in the editor in the first parameter, and you're good to go! Just as an example:
    PHP Code:
    [playercall hyp_fnc_traceFire;
    [
    heli1call hyp_fnc_traceFire;
    [
    car1call hyp_fnc_traceFire
    Would cause bullets fired by the player's unit, heli1, and car1 to be traced with default options.

    To give you yet another idea for what you can do, the following code will cause all units on the map to have their projectiles traced with team-specific colors that disappear after 3 seconds:
    PHP Code:
    {
        if (
    faction _x == "OPF_F"then {
            [
    _x, [1,0,0,1], 32nil3call hyp_fnc_traceFire
        };
        if (
    faction _x == "BLU_F"then {
            [
    _x, [0,0,1,1], 32nil3call hyp_fnc_traceFire
        };
        if (
    faction _x in ["IND_F""IND_G_F""CIV_F"]) then {
            [
    _x, [0,1,0,1], 32nil3call hyp_fnc_traceFire
        };
    } forEach 
    allUnits
    In Use:

    Here's Dslyecxi's recent video featuring this script with his now-implemented modifications:


    And here's a snazzy video by Jester814 that makes fairly heavy use of the original version of this script:


    Notes/Known Bugs:
    - Many optics, and some vehicle interiors (Pawnee comes to mind) do not play nicely with the drawn lines. A chunk of space floating in front of the sight will block out the lines behind them, so I recommend testing without optics. The Pawnee, for whetever reason, does not show any drawn lines at all in first person, so you need to enter third person to see lines from it.
    - Water *mostly* works. Try it and you'll see what I mean. My guess is that it's getting the position relative to the sea level fine, but then has the height of the wave below it added, causing some mildly bendy lines.
    - You may notice that the "fired" eventHandler has a seemingly redundant parameter added on. This actually is an interesting consequence of having the code spawned, as it seemed the scheduler put just enough of a delay between the event firing and the code within the spawn executing that the first gotten position of the bullet would be a few meters away. So this gets the first position before the spawn, and passes it in, and all seems to work well. Note that I don't actually have much scientific evidence to backup my theory, just that the first gotten position within the spawn was certainly late, while outside the spawn it was just fine.
    Last edited by Hypnomatic; Oct 27 2013 at 03:13. Reason: Update 10/26/2013

  2. #2
    sounds real cool. giving it a try now. thanks!

    edit - couldnt get it working. pity. sounds interesting.
    Last edited by twisted; Sep 15 2013 at 06:28.

  3. #3
    Nice, it works well for me. Interesting to see the performance cost of lots of simple 3D lines too!

    Here's a quick fix to get the traces working over the ocean:
    Code:
    ...
     //Assemble the array of positions and push it to the global array
                waitUntil {
                    if (isNull _bullet) exitWith {true};
                    _positions set [count _positions, position _bullet];
                    firedBullets set [_index, _positions];
                };
    ...
    Last edited by ceeeb; Sep 15 2013 at 07:45. Reason: Revised code and removed link to feedback tracker, since the position format uses different datums over land and sea!!!

  4. #4
    Quote Originally Posted by twisted View Post
    sounds real cool. giving it a try now. thanks!

    edit - couldnt get it working. pity. sounds interesting.
    Just put all that code into init.sqf, loaded the mission and preview.

  5. #5
    Quote Originally Posted by twisted View Post
    sounds real cool. giving it a try now. thanks!

    edit - couldnt get it working. pity. sounds interesting.
    Yeah, as Kylania noted, just put the chunk of code in your init.sqf and preview the mission. Also note that you need to add at the very least something like:

    PHP Code:
    [playercall hyp_fnc_traceFire
    To make it draw lines for your player, as just the main chunk of code doesn't specify any units to watch. If you try that, it hopefully "should" work.

    Quote Originally Posted by ceeeb
    Nice, it works well for me. Interesting to see the performance cost of lots of simple 3D lines too!

    Here's a quick fix to get the traces working over the ocean:
    ...
    Yeah, how this hit performance was interesting to watch. Now, I'm not 100% sure about how the Draw3D eventHandler works, so I need to do a few tests to see how much of the performance hit was caused by the drawLine3D itself, and how much was caused simply by the sheer number or elements in the arrays to iterate through.

    Also I'll plug in your change tomorrow. Don't have the chance to test it tonight unfortunately, though. Thanks!

  6. #6
    Master Gunnery Sergeant Tajin's Avatar
    Join Date
    Jun 4 2009
    Location
    Bavaria, GER
    Posts
    1,094
    I've always been doing that with non-moving particles instead of lines. Might wanna give that a try...

    Here's how my old script worked (adapted on the fly – untested in ArmA3):
    PHP Code:
    // this addEventHandler ["fired", { [_this] spawn ArA_fnc_tracebullet; };

    ArA_fnc_tracebullet = {
        
    _unit _this select 0;
        
    _bullet _this select 6;
        
    _start velocity _bullet;
        
        
    _lifeTime 2//seconds
        
    _limit 1000 //meters
        
        
    while {(!isNull _bullet) and (velocity _bullet 0) and (player distance _bullet _limit)} do {
            
    _vel velocity _bullet;
            
    _r _vel _start;
            
    _g _vel _start;
            
    _b 0;
            
    drop ["\Ca\Data\missileSmoke","","Billboard",0.1,_lifeTime,[0,0,0],[0,0,0],0,1.275,1,0,[0.1 0.0005*(player distance _shot),0.1],[[(player distance _shot) / _limit,1-(player distance _shot) / _limit,0,(player distance _shot) / 25],[_r,_g,_b,1]],[1,0],0,0,"","",_shot];
            
    sleep 0.01;
        };
    }; 
    I've limited it to trace bullets for only 1000 meters.

    Particle lifetime and size can still be adjusted. Right now, they particles get bigger, the further they are away. So this was originally meant to be viewed from the shooter-point of view, not for walking around the bulletpaths. Using a longer particle-lifetime will make that possible.
    Last edited by Tajin; Sep 18 2013 at 10:11.
    Spoiler:

    There are many capable people roaming this forum, willing to spend some of their time to help others out. If you have a problem, it surely isn't too much to ask that you take the time to describe it properly.
    Thanks.
    Please don't ask for script-support via PM. Write it in a thread, so that everyone can benefit from it!

  7. #7
    Sergeant Major IndeedPete's Avatar
    Join Date
    Jun 14 2009
    Location
    Niedersachsen, Germany
    Posts
    1,873
    Very cool! Plus it proofs that you probably shouldn't hide behind a portable toiled in a firefight.

  8. #8
    Staff Sergeant rehtus777's Avatar
    Join Date
    Jan 19 2011
    Location
    Near Abilene, Kansas - Home of General Eisenhower, Sheriff Wild Bill Hickok, & Superman (Clark Kent)
    Posts
    382
    Sweet Script - Thank you. Now, if I only had a wind direction / speed indicator, sniping practice would be set.

  9. #9
    Can't get it to work, using the dev build.
    I put it to init.sqf + added [player] call hyp_fnc_traceFire;
    I have "clear lines" in the action menu, but nothing happens when I fire the weapon. Problems with the dev build, or with my graphics settings?

    Edit: Nevermind... After restarting Arma, everything is working...

  10. #10
    I got it to work by realizing all the code goes in the init.sqf. it's great.

Page 1 of 7 12345 ... LastLast

Similar Threads

  1. Projectile Types
    By Ub3rObama in forum ARMA 2 & OA : ADDONS - Configs & Scripting
    Replies: 0
    Last Post: Aug 2 2013, 05:05
  2. Lengthy timeout when accessing Controls menu. Need help tracing cause.
    By Grumpy in forum ARMA 2 & OA - TROUBLESHOOTING
    Replies: 0
    Last Post: Jul 28 2011, 20:28
  3. Local path override of .pbo path
    By callihn in forum ARMA 2 & OA - SUGGESTIONS
    Replies: 8
    Last Post: Jun 13 2010, 21:10
  4. Multiplayer Coding (Fun Fun Fun :P)
    By Rommel in forum ARMA - MISSION EDITING & SCRIPTING
    Replies: 2
    Last Post: Mar 10 2008, 13:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •