[beta] Fast projectiles support

Author Topic: [beta] Fast projectiles support  (Read 5349 times)

This is a support script that allows you to create the illusion of projectiles that can travel over the maximum velocity of 200. It works by doing a number of raycasts over time and using an animated static shape. It includes an example weapon which is just a copy of the default gun that uses this system instead.

To use it, you need to create a projectile with special values. For example:
Code: [Select]
datablock ProjectileData(staticHitscanGunProjectile : gunProjectile)
{
    projectileShapeName = gunProjectile.projectileShapeName;

uiName = "";
effectiveRange = 150; // effective range
totalRange = 2000; // total range

unitsPerSecond = 1500; // how many torque units the projectile should travel in one second
// the default static shape is designed for ranges in
// the 800 - 2000 u/s range, anything slower will lag
// visually.

gravityScale = 0.7; // scale gravity effect outside effective range
swayMod = 0.5; // scale wind effect outside effective range

spawnFakeProjectiles   = true; // use animated static shape to give the illusion of a visible projectile
tracerEffect = false; // use red tracer effect

scaleCalibre = 0.3; // bullet scale on diameter axis
scaleLength = 1;        // bullet scale on length axis

isSupersonic = true; // enable/disable supersonic crack effect on near miss
isSuppressive = true; // enable/disable suppression effects
suppressionRadius       = 18; // distance the bullet must near-miss the player by in order to cause suppression effects

allowRicochet = true; // enable/disable bullet ricochet
ricoMinimumAngle = 40; // minimum angle that can ricochet
ricoChanceCurve = 5; // the higher, the more common ricochet is
ricoRarity = 3; // higher = less common rico
// https://www.desmos.com/calculator/p6ywpi0sud

particleEmitter      = "";
};

To create a projectile with this system, call this function:
createStaticHitscan(%client, %muzzlePoint, %muzzleVector, %projectileDatablock, %spread, %zero);

Spread is built in, all you have to do is pass it a value. It also has a zero value which allows you to adjust the trajectory up and down.

This system will simulate gravity when the projectile leaves the effective range, and can also simulate wind based on the value of $WindVector (e.g. "0 0.001 0" simulates wind on the positive y axis)

The code is pretty heavily commented for anyone who wants to use it. I haven't tested this in situations with heavy latency or with complicated minigame checks so please let me know if you find any bugs.

Download
Previous Version
Support_FastProjectiles
« Last Edit: March 24, 2018, 05:00:00 AM by Rally »


yes i can finally make my guns not suck absolute ass because of the usual "do i go forgeted up hitscan or snail slow projectiles?"

Does it still forget up bullet trails and emitters?

does this happen to have support for attaching an emitter to the projectile? for example like how the horse ray doesn't use a model, but rather JUST an emitter for its projectile... could this accommodate that? seems sweet regardless though!

does this happen to have support for attaching an emitter to the projectile?

There is no projectile until a hit is detected, so you lose projectile functionality, including emitters, sound, and lights. I could think of a couple workarounds but they'd all create ghosting lag lol


Dude this is forgetin amazing A+

add fly by radius sound support

add fly by radius sound support

I've actually been working on this for the next update, as well as 'suppression' effects and ricocheting

EDIT: I also managed to overlook the fact that gravityMod is a default projectile field and you won't be able to set it higher than 1, so I'll be changing it to gravityScale in the update lol
« Last Edit: March 24, 2018, 02:20:49 AM by Rally »

Ok made an update:

New weapon prefs:

isSupersonic - If true, bullets will create a cracking noise when they pass by players. If false, they'll create a whizzing sound as they pass by.
isSuppressive - Enable/disable suppression effects, basically just small amounts of whiteout and vignette that occurs and fades out over time when a bullet passes by you.
suppressionRadius - How close the player has to be to the bullet in order to experience a suppression effect, including the near-miss sound.

allowRicochet - Enable/Disable ricochet. If enabled, when a bullet hits a surface, it will determine whether or not it should ricochet. If it does, it will look for a projectileData function called projectileData::onRicochet(%this, %obj, %pos, %reflectVec) which allows you to give custom functionality to the projectile when it ricochets. If this function doesn't exist but you still have this field set to true, it'll just do another hitscan using the ricochet vector.
ricoMinimumAngle - The maximum angle that a bullet can ricochet off of. For example, setting this to 40 will mean a bullet can only ricochet if it hits a surface at 40 degrees or less.
ricoChanceCurve - A coefficient that scales how less likely a bullet is to ricochet the greater the angle
ricoRarity - A value that flat decreases the chance for a ricochet to occur.

Weapon_hitscanGun has been updated with new comments and includes an example of how to create a ricochet system with custom ricochet projectiles

New server prefs:

$Pref::Suppression::Vignette - Enable/Disable vignette effect when suppressed, default true
$Pref::Suppression::VignetteColor - Color of the vignette when suppressed, default "1 0 0" (red)

$Pref::Suppression::Whiteout - Enable/Disable whiteout effect when suppressed, default true
$Pref::Suppression::WhiteoutIntensity - Strength of the whiteout effect at the epicenter, default 0.25

$Pref::Suppression::IgnoresWalls - Determines whether or not you can be suppressed through walls. default false.

Functions:
I added a new function called Player::onSuppressed(%player, %mag) that does nothing, it's purpose is that you can package it with your add-on and give custom suppression effects if you're not happy with the default ones. This will be called if isSuppressive is set to true regardless of whether or not whiteout and vignette is enabled. The %mag is a 0 - 1 value based on how close the player is to the epicenter vs the projectiles suppression radius.

NOTE: The gravityMod field for projectiles has been changed to gravityScale as to not conflict with default game functionality. You'll have to update your addons to work with this version.

Support_FastProjectiles
« Last Edit: March 24, 2018, 05:00:12 AM by Rally »

no sound customization?

I figured hosts could just replace the sound files but I guess it wouldn't be too hard to make a pref system for it

I figured hosts could just replace the sound files but I guess it wouldn't be too hard to make a pref system for it
not accounting for different types of guns that would make different sounds?

Then I could have it check the projectile datablock for custom sounds. Can you give me an example of a system that you would find most useful?