-
Notifications
You must be signed in to change notification settings - Fork 20
Muzzle Flash
Wikipedia: Muzzle flash is the light — both visible and infrared — created by a muzzle blast, which is caused by the sudden release and expansion of high-temperature, high-pressure gases from the muzzle of a firearm during shooting.
This method is more customisable, but is limited to the player that has shot the gun. Animation state is not passed to other players at the moment, and a proper system needs to be built to handle it. This is a possible expansion for the future, however.
You need to use a model extending from ModelFlash, you can use this template to convert a toolbox-exported model, but you will need to do this step by hand.
package com.flansmod.client.model.YOURPACKAGENAMEHERE;
import com.flansmod.client.model.ModelFlash;
import com.flansmod.client.tmt.ModelRendererTurbo;
public class ModelYOURMODELNAMEHERE extends ModelFlash
{
public ModelYOURMODELNAMEHERE()
{
int textureX = 64; //The x-size of the texture
int textureY = 16; //The y-size of the texture
// First number should always be 3, as this is how many animation 'frames' Flansmod is expecting. The second number is how many parts should be in each frame. Here, we're using 1 part in each frame.
flashModel = new ModelRendererTurbo[3][1];
// Copy and edit your TB-exported model so that each part is in flashModel - you need to add the flashModel[x][y] stuff and replace the model part that TB assigns.
// [0][0] means flash frame 0, part 0 (Frame 1, Part 1) (Remember arrays start from 0! the 0th element is the first item in the array!
flashModel[0][0] = new ModelRendererTurbo(this, 0, 0, textureX, textureY);
flashModel[0][0].addBox(0F, 0F, 0F, 2, 2, 2);
// [1][0] means flash frame 1, part 0 (Frame 2, Part 1)
flashModel[1][0] = new ModelRendererTurbo(this, 0, 0, textureX, textureY);
flashModel[1][0].addBox(0F, 0F, 0F, 5, 5, 5);
// [2][0] is flash frame 1, part 0 (Frame 3, Part 1)
flashModel[2][0] = new ModelRendererTurbo(this, 0, 0, textureX, textureY);
flashModel[2][0].addBox(0F, 0F, 0F, 20, 2, 2);
// You MUST define all three flash stages, otherwise the game will probably crash.
}
}
Save this model to your models folder, you can then use it in your gun config, with an appropriate texture:
FlashModel YOURPACKAGENAME.YOURMODELNAME
FlashTexture YOURTEXTURENAME
Next, you need to setup the positions that the model will render at. You do this in your gun's java model, in the same part as other animation settings. You need to add the following lines:
muzzleFlashPoint = new Vector3f(0.8F, 0.8F, -1F);
defaultBarrelFlashPoint = new Vector3f(0.1F, 0.1F, 0.1F);
Change the values to those that you see fit. muzzleFlashPoint
defines the 'base' point that the flash will appear at. 0,0,0 is the player's hand, and the units are blocks - divide all your values by 16F to get pixels.
defaultBarrelFlashPoint
specifies an offset from muzzleFlashPoint to be used when there is no barrel attached - unless you're using a default barrel that is replaced when adding a barrel attachment, this should be set to 0,0,0. Otherwise, set this to the offset (in blocks) that your default barrel moves the point.
Barrel attachments can move the point at which the flash appears, or hide it completely. To adjust the offset when this attachment is equipped, in the attachment's Java model, add this line:
attachmentFlashOffset = new Vector3f(1F, 2F, 3F);
To remove muzzle flash when a certain attachment is equipped, add this to your attachment's config file:
DisableMuzzleFlash true
The particle based muzzle flash system can be visible to all players. The logic for this is much more complex, see the logic diagram before attempting to configure.
The logic flow can be seen in the screenshot below. Only paths that result in a muzzle flash to the current player are shown, any other paths are ignored.
In words:
ShowMuzzleFlashParticles is true (Default)
AND
There is no attached barrel, OR the attached barrel does not disable muzzle flash
=> Other players will now see the particles. For the shooter to see the particles as well:
The gun has no set flash model (So no flash model + particles)
AND
The player is NOT in first person OR ShowMuzzleFlashParticlesFirstPerson is true (Default = false)
MuzzleFlashParticle
sets the type of particle to use. flansmod.muzzleflash
has been developed specifically for this, and will be at full brightness to make it visible in dark areas. Any other particle from (Particle Types)[https://github.com/Unknown025/Flans-Mod-Plus/wiki/Particle-Types] can be used instead.
To change the size of the particles, use MuzzleFlashParticleSize
.
ShowMuzzleFlashParticle
uses the default value set in flansmod.cfg
. Any other value will override this. If set to false, no particles will be shown for this gun at all.
ShowMuzzleFlashParticleFirstPerson
is by default false. If true, the shooter will be able to see muzzle flash particles in first person (provided other conditions shown in logic flow). This is off by default because of the shortcomings described in Positioning.
FM+USE guesses the position of the gun in world space, based on the player's reported rotations. This is NOT accurate, and the particles may appear slightly to the side of where they need to. For this reason, the effect may not look right from either first person, or at close proximity to the shooter.
First, the hand position is calculated. The gun model's muzzleFlashPoint
, defaultBarrelFlashPoint
and any attachment's muzzle offset variables will be used. If not, a hardcoded 'default' value will be used.
To alter how these calculations occur, you can set the two values in the gun's config:
MuzzleFlashParticleShoulderOffset [x,y,z]
will move the position of the player's shoulder joint, moving their arm. X is forward, Y is up and Z is to the side relative to world space. This shouldn't need to be changed.
MuzzleFlashParticleHandOffset [x,y,z]
will move the position of the particle relative to the gun/arm. X is along the arm, Y is perpendicular to the arm upwards, and Z is to the side. Use this if you want to move the position of the particle relative to the gun.