• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Weapons

Status
Not open for further replies.
I'm having some problems with my weapons system:

1. The projectiles sometimes go through a unit without colliding. This is especially a big problem for my fast projectiles. Projectiles script:
JASS:
//--------------------------------------------------------------------------------------------------
// Trigger: Projectiles
//--------------------------------------------------------------------------------------------------
bool gt_Projectiles_Func (bool testConds, bool runActions) {
    // Variable Declarations
    unit lv_u;
    fixed lv_angle;
    int lv_cv;

    // Variable Initialization
    lv_u = null;
    lv_angle = 270.0;
    lv_cv = 0;

    // Actions
    if (!runActions) {
        return true;
    }

    UnitGroupLoopBegin(gv_projectileUG);
    while (!UnitGroupLoopDone()) {
        lv_u  = UnitGroupLoopCurrent();
        lv_cv = FixedToInt(UnitGetCustomValue(lv_u, gv_CVS));
        UnitSetPosition(lv_u, PointWithOffsetPolar(UnitGetPosition(lv_u), gv_projSpeed[lv_cv], gv_projDirection[lv_cv]), true);
        UnitGroupLoopStep();
    }
    UnitGroupLoopEnd();
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_Projectiles_Init () {
    gt_Projectiles = TriggerCreate("gt_Projectiles_Func");
    TriggerAddEventTimePeriodic(gt_Projectiles, 0.02, c_timeReal);
}
2. Knockback. I have a working system but I use fail math.
JASS:
gv_projSpeed[lv_cv2] = gv_projKnockback[lv_cv] - gv_uMass[lv_cv2];
3. Spray. I currently just use RandomFixed and don't do a proper spray; I also can't increase/decrease spray such as should be the case with a minigun.
JASS:
UnitCreate(1, "Projectile", 0, lv_p, lv_projstartpt, lv_angle + RandomFixed(-11.5, 11.5));
4. I can't stop the muzzle-flash & weapon-sound from playing when a unit with no ammo takes a shot because I have that all attached to the weapon in the data manager since I can't script sounds/animations in a way that works. When I just play a sound through scripting any sounds being played via the normal game such as zerg death sounds will play instead of the scripted sound, which will only play when there's no other noise to conflict with it. I don't even know if there's a way to make the muzzle flashes appear correctly.
5. I have a hard time deciding what damage weapon projectile should do... right now I just try to balance all the guns currently existing but I think I should do this some other way then just guessing.
  • Weapon Damage
    • DMG Flamethrower = 0.1 <Real (Constant)>
    • DMG Assault Rifle = 4.2 <Real (Constant)>
    • DMG Shotgun = 2.35 <Real (Constant)>
    • DMG Rifle = 35.0 <Real (Constant)>
    • DMG Micro Uzi = 1.33 <Real (Constant)>
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
1. That is because you are using a key frame system. The distance the projectile appears to travel is not checked as it does not physically travel it. Only soultion is to use better vector maths so that you get a line between the current and the future displacement target of the projectile.

2. Use simple physics. Remember that momentum is conserved in collisions. Thus your knockback should be giving units cerain momentums which then are devided by their mass to get a velocity. This velocity causes friction forces to occur which cause an object to decelerate.

3. You are unclear. What is a "proper spray"?

4. Redesign your data structure. Remember that the weapon should only be active if there is ammo. Thus consider a validator maybe. You might also be able to remove the weapon using script for better interaction with your current systems.

5. Depends on game ballence. Weapons with good ammo efficiency should deal less damage than those with poorer ammo effeciency. Huge knockback might be advantageous in your map thus such weapons need to deal reduced damage. Long range weapons should deal less than short range to compensate for the saftey range provides. Some enemies should take more or less damage from certain weapon types to encourage variety. There is no way to calculate exact numbers, you just need to make sure everything has a purpose and is usable.
 
Your post wasn't very helpful... by spray I mean the cone-shaped firing with bloom... the more you fire the less accurate your guns gets. I don't know how to do it as a cone though only as a pyramid-shape. I would also like to know how to find the point the projectile should be travelling too right away the moment you fire for very fast projectiles.

Can you post math for knockback? Otherwise I'll just have to look at a script done in some other language I guess.

How can I use a validator with my script?

Edit 4: It took me forever but I just managed to get the projectiles to move via giving them move orders. Now the collision appears to be perfect. I have to terminate the projectiles when they hit the map edge though so I might expand the map edge without expanding the camera bounds or something. I also can't just give them one order to move to a very far away location or they'll move at the wrong angle if the target point would be outside the map & I don't know how I'd move them on the z-axis.

Edit 5: I really want to know how to do arcs btw for things like grenades... I don't know :<

Edit 6: Just realized using move order commands massively messes up my game... is there some way I can apply something that moves the unit forward using the data manger?

Edit 7: Maybe for highspeed projectiles I should just have some tracer round projectiles fire out every xth round that don't actually do anything and are just for show, while the actual projectile collision is done in a line and is instant? How do I do this?

I'm have a lot of trouble with sounds btw. Fully-automatic sustained fire + trying to get a custom sound to work with it = sounds awful.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
by spray I mean the cone-shaped firing with bloom... the more you fire the less accurate your guns gets.
For cone like spray you work out an angle for the cone. You then rotate this angle by a random angle. If you uint is looking along t y axis, you firstly work out a xy angle for your cone and then you rotate than angle along the xz axis to make your random cone. Think about vectors and rotational transformations. The increasing spray is just a mater of increasing the cone angle over time. The bloom will require an appropiate light emmiter attached to the gun nozel.

I would also like to know how to find the point the projectile should be travelling too right away the moment you fire for very fast projectiles.
You can predict the position. Remember that velocity multiplied by time gives you a displacement.

Can you post math for knockback?
m1*u1 + m2*u2 = (m1 + m2)v
Solve for V. 1 and 2 represent quantities for objects. Your projectile could be 1 and the enemy 2. Be aware that realistic quantities for projectiles will result in shit knockback as guns in reality do not send you flying in a movie. For your game you might wish to make bullets more like the weight of shells to send stuff flying backwards.

Alternativly you could just use p=m*v solved for v where p is a momentum you arbitrailly assign prokectiles to transfer and m is the mass of the unit (which usually is based on unit actor size).

Friction is applied by reducing velocity of a unit. A good friction structure would have a df/dv value (force of friction is based on current velocity) with the exact value being based on the surface the unit is sliding on and the footprint of the unit sliding. A constant component is also needed to prevent knockback being subject to only exponential decay (thus allowing units to actually stop).

How can I use a validator with my script?
Well the hackery approach would be to make a validator or requirement that depends on the presence of an upgrade which you can then learn and unlearn at will (yes SC2 supports unlearning upgrades).

A more solid and recommended approach is to just make a buff behaviour (out of ammo) which disables all the units attacks. This is given to units which run out of ammo. It is removed from units when they obtain ammo (by changing weapons or by having ammo restored to them).

Edit 5: I really want to know how to do arcs btw for things like grenades... I don't know :<
You can get a parabola by a simple z=x^2+x+c formula. X is how far the projectile has gone along its arc path so in reality is eithor a shared variable between the projectile displacement and the the arc or is a cast specific ration of x and y.

You could also try the physical approach and give the gernade a vector which you then let gravity effect.

If you just want an ability to lob a gernade dead centre at the target location all you need is to launch a projectile towards the target location and give it an appropiate mover (which has been set to form a parablola). For an example parablola mover, see the reapers anti-building attack which is a gernade toss.

is there some way I can apply something that moves the unit forward using the data manger?
Try using the force effect. It is what the mothership's votex uses to suck units in and what hybrid maar uses to knock you back.

Edit 7: Maybe for highspeed projectiles I should just have some tracer round projectiles fire out every xth round that don't actually do anything and are just for show, while the actual projectile collision is done in a line and is instant? How do I do this?
Seperate the graphics from the actual working part. The graphics could just be done in the data editor using actors. The tracer is done eithor using a high frequency itterator method (like the hellions line pierce or the snipe of raynor on charr) or you use a large scope unit itteration and appropiate maths to make sure all units fall within a line. The maths approach is the most accurate and considered the fastest but the itterative approach can easilly be made in the data editor alone (like the hellion).

I'm have a lot of trouble with sounds btw. Fully-automatic sustained fire + trying to get a custom sound to work with it = sounds awful.
Use actors for sounds. Rapid fire attacks need a substained sound (a single sound containing many shots) to prevent rapid depletion of sound channels. Avoid letting too many units die at once to prevent depletion for unit death sounds.
 
Status
Not open for further replies.
Top