Fixing muzzleFlash in 3rd person view

Hi, I making a custom muzzleflash for my Airboat gun. In 1st view everything is fine (the muzzle is pined to ViewModel’s muzzle Attachment) but if I toggle camera or thirdperson the muzzleflash is pined to camera’s (or 3rd person camera view) attachment.

Please Help me

http://imageshack.com/a/img909/3917/EVK2ty.jpg

http://imageshack.com/a/img674/7478/dAVTtT.jpg

Look up fire events… Also show us the code. In the meantime here’s the fire-event code I use, and how I do muzzle flashes for thirdperson and firstperson:

CLIENT


SWEP.CSMuzzleFlashes		= true

//
// Fixes Double MuzzleFlash and other issues = Josh 'Acecool' Moser
//
function SWEP:FireAnimationEvent( _pos, _ang, _event, _options )
	-- Disables animation based muzzle _event
	if ( _event == 20 ) then return true end

	-- Disable thirdperson muzzle flash
	if ( _event == 5001 ) then return true end
end
	

SHARED


	local _p = self.Owner;
	local _effect = EffectData( );
	_effect:SetOrigin( _p:GetShootPos( ) );
	_effect:SetEntity( self );
	_effect:SetStart( _p:GetShootPos( ) );
	_effect:SetNormal( _p:GetAimVector( ) );

	// You'd need to replace 1 with the attachment you're using.
	_effect:SetAttachment( 1 );

	// Timer otherwise the effect will show up in the wrong place
	timer.Simple( 0, function( )
		if ( !self.Owner ) then return end

		// Prevents the client from seeing more than 1 / spam because of how sweps work
		if ( !IsFirstTimePredicted( ) ) then return; end

		// Apply the effect
		util.Effect( "gunsmoke", _effect );
	end );
	

The issue may be with the thirdperson fire-event enabled or you’re not setting up the effect manually.

thanks i will test it

Show us your code… Show us how you’re creating the effect.

ok. There’s my code:



function SWEP:FireAnimationEvent(pos, ang, event, options)

    if ( event == 21 or event == 22 ) then
	    
		local muzzle = EffectData();
        muzzle:SetOrigin( pos )
		muzzle:SetEntity( self.Owner:GetViewModel() )
		muzzle:SetAngles( ang )
		muzzle:SetAttachment( 1 )
		
		
		util.Effect( "AirboatMuzzleFlash", muzzle );
			
		return true
	end
		
end


You still didn’t disable the thirdperson event, plus the muzzle flash usually gets called in ShootEffects. Also, you didn’t enable / disable CS muzzle flashes.



function SWEP:FireAnimationEvent(pos, ang, event, options)

    if ( event == 21 or event == 22 or event == 5001 ) then
	    
		local muzzle = EffectData();
        muzzle:SetOrigin( pos )
		muzzle:SetEntity( self.Owner:GetViewModel() )
		muzzle:SetAngles( ang )
		muzzle:SetAttachment( 1 )
		
		
		util.Effect( "AirboatMuzzleFlash", muzzle );
			
		return true
	end
		
end


Right?



function SWEP:FireAnimationEvent(pos, ang, event, options)

    if ( event == 21 or event == 22 ) then
	    
		local muzzle = EffectData();
        muzzle:SetOrigin( pos )
		muzzle:SetEntity( self.Owner:GetViewModel() )
		muzzle:SetAngles( ang )
		muzzle:SetAttachment( 1 )
		
		
		util.Effect( "AirboatMuzzleFlash", muzzle );
		
	end
	
	if ( event == 5003 ) then
	local tpmuzzle = EffectData();
	tpmuzzle:SetOrigin( pos )
	tpmuzzle:SetEntity( self )
	tpmuzzle:SetAngles( ang )
	tpmuzzle:SetAttachment( 1 )
	
	util.Effect( "AirboatMuzzleFlash", tpmuzzle );
		
		return true
	end
		
end


Still not working :frowning:

Put your muzzle flash into ShootEffects ( which should be called by PrimaryAttack, or ShootBullet… ); The Fire Event thing is to prevent a muzzle-flash from being created on certain events. You’re creating one anyway…

Also, your thirdperson muzzle-flash should NOT be using self.Owner:GetViewModel( ). It should use self / self.Owner:GetActiveWeapon( ) – same thing, use self…

The reason your flash is so far off in thirdperson is because it’s looking for the view-model, which IS around that area of the screen in thirdperson ( overlay the screenshots, regardless of angle, it is the same spot… then go into firstperson to see if the muzzle is in that same spot ).

OK I will test