Viewmodel Muzzleflash position

hiya FP.
Today i’ve been struggling with the repositioning of the muzzleflares on my custom SWEP. The whole swep visually is a SWEP creation kit weapon, with two guns on either side (Let’s say its an akimbo weapon or something)
What i’m trying to do is reposition the muzzleflash to fit the weapons on either side, using a switching function after every shot to switch between the two. I haven’t been very successful, and the only results i can get is the muzzleflash originating on the weapon’s muzzle, regardless of what i do.
So, in basic, how can i change the position of the muzzle effect?
here’s code:
if CLIENT then
function SWEP:MuzzleEffect(elname, pos)
local viewm = self.Owner:GetViewModel()
local vm = self.VElements[""…elname…""].modelEnt
local muzzleflash = EffectData()

    muzzleflash:SetOrigin(vm:GetPos() + vm:GetForward() * 60) -- testing purposes, usually just vm:GetPos + pos
    muzzleflash:SetStart(vm:GetPos() + vm:GetForward()* 60) -- same as above
	muzzleflash:SetEntity( viewm ) -- actual viewmodel
	muzzleflash:SetAttachment( viewm:LookupAttachment("muzzle") ) -- needed attachment to make this work
	muzzleflash:SetScale(1) -- a function that seems to be designed to scale the size of the effect, Doesn't do squat if i change it.
	print(muzzleflash:GetOrigin()) -- Returns more or less what i expect it to (Current Position of the viewmodel + offset of the muzzles of left/right gun)
util.Effect("ChopperMuzzleFlash", muzzleflash, true, true)


This in general has returned the same thing over and over, a muzzleflash on the muzzle of the original ViewModel. I’m unable to edit its position. How can i do this?
Thanks in advance!


bump. Anybody at all?

Could you create another viewmodel in your VElements array, invisible, positioned/parented where you want, and use that for the muzzleeffect only? Since you seem to have to use SetAttachment

i tried this method first, it didn’t succeed as well as i’d hope.

Instead of SetAttachment for the effect, you could get the attachment ( which returns .Pos, and .Ang ), and modify the attachment, then set the position and angle normally on the effect. Using that method, you could easily adjust the position and/or the angle.

So basically, the muzzleflash always appears on the first gun, right? Do you have any reliable way to get the muzzle position of the second gun?

Also what happens if you don’t set an entity and an attachment for the effect? From your comments, it looks like SetOrigin and SetStart change absolutely nothing, if that’s true then it’s probably the way the effect was coded and you won’t be able to change that.

There’s a way around that using dummy entities but first you need a reliable way to get the muzzle position on both guns at any time.

ChopperMuzzleFlash is defined in this file around line 538
It seems to only use the attachment and not the start parameter (but does use origin for something).
A possible alternative is to recreate this effect in lua and make it use the given positions instead of the attachments. From the source it is just creating a particle emitter that sprays out particles of effects/combinemuzzle[0/1]., but then it calls CreateMuzzleflashELight (with the origin) which I’m not sure about, it creates some kind of entity light?

[editline]7th September 2013[/editline]

That ‘entity light’ is just a DynamicLight I believe, so it could definitley be all recreated in Lua.

Modify? As in, Attachment:SetPos() and then link it to the attachment?

[editline]7th September 2013[/editline]

Yeah, appears on the viewmodel muzzle attachment of the first gun, always.

[editline]7th September 2013[/editline]

It simply doesn’t show up when i do that. No errors.

[editline]7th September 2013[/editline]

Weird that it does that. I’ll use a normal muzzleflash effect and try again.

Just a particleemitter? i could probably do that. As long as i can get the effect to position properly i’m set to go.

If you PrintTable Attachment, you get Pos = Vector( … ), Ang = Angle( … )

You could simple change the position and angle, by referencing table.Pos or table.Ang; and instead of using SetAttachment for the effect, pass in position and angle ( ensure the effect is coded to accept either attachment OR pos/ang )

You can’t change the default position, since you can’t edit attachments positions without recompiling the model. But you can always offset your custom effects, etc.

i’ve tried doing it without the attachments. i still have to SetEntity to the viewmodel though

Seriously?? Read my post please! An attachment, when you PRINT it out, is a table that looks like this:

[lua]local _table = { Pos = Vector( 111, 222, 333 ), Ang = Angle( 0, 90, 10 ) }[lua]

Simply create a variable pointing to the attachment. We’ll call that _table, as it’s the same as the _table that I wrapped in Lua tags.

[lua]_offsetPos = Vector( 0, 0, -5 );
_offsetAng = Angle( 0, 90, 0 );
_table.Pos = _table.Pos + _offsetPos;
_table.Ang = _table.Ang + _offsetAng;[/lua]

But, you have to make sure that your effect can take an input of Positions and Angles!!!

Additionally, for your _offsetPos and _offsetAng be sure to RotateAroundAxis, and apply the proper mathematics otherwise if you stand still and rotate in place, it will not be attached with it properly…

Handsome Matt keeps harassing me and marking my posts dumb, yet it provides your answer…

I wouldn’t recommend using Ang+Angle or Pos+Vector, it could mess up position, use ang:RotateAroundAxis for angles and ang:Up()/ent:GetUp() functions for position.

That’s what I said. Can you not read???

I’m being rated dumb by MATT WHO IS HARASSING ME, and you are not reading my post???

Robot I seriously expected you to know how to read?


See this in my post???
Additionally, for your _offsetPos and _offsetAng be sure to RotateAroundAxis, and apply the proper mathematics otherwise if you stand still and rotate in place, it will not be attached with it properly…

Robot, you’re basically echoing me in each of your posts.

I didn’t read the thread at all, I answered OPs last post.

You should’ve added that into the code since that’s all I’ve read.
I know how it sounds, but you first suggest one way and then correct yourself later, why not just post the proper way from the start? You should know that people are lazy and tend to just copy and paste the code.

Sorry about that, was late at night and i could barely understand what you were saying.
I’ts still morning and im not keeping up all the way, so could i ask one of you fine gentleman to elaborate on how to modify the pos?
I’ve got the angles i believe, tell me if im on the right track:

if CLIENT then
function SWEP:MuzzleEffect(elname, pos)
local viewm = self.Owner:GetViewModel()
local vm = self.VElements[""…elname…""]
local muzzleflash = EffectData()
local _vmtbl = viewm:GetAttachment(viewm:LookupAttachment(“muzzle”))
local newpos = _vmtbl.Pos
local newang = _vmtbl.Ang
newang:RotateAroundAxis(newang:Up(), vm.angle.y)
newang:RotateAroundAxis(newang:Right(), vm.angle.p)
newang:RotateAroundAxis(newang:Forward(), vm.angle.r)
newpos = vm.pos + _vmtbl.Pos
muzzleflash:SetEntity( viewm )
–muzzleflash:SetAttachment( viewm:LookupAttachment(“muzzle”) )

util.Effect("AirboatMuzzleFlash", muzzleflash, true, true)


[editline]8th September 2013[/editline]

Would it be more conventional for me to just use a particleemitter?
im a bit wary of it, i hear that having alot of them is just a downright bad idea, and you should end particleemitters when they’re done. Would i just remove it when the player holsters the weapon or dies?
Thanks for the replys, i wouldnt know where to go past that.

Careful, Lua particle emitters emit particles in “absolute coordinates”, which means that if you fire while running forward, the particles will not follow your gun and will instead stay behind, which will look wrong. There is a way to get the particles to follow an attachment point but it’s rather tricky as you need to spawn the emitter at the map origin (0,0,0), use cam.Start3D to so it gets rendered at the desired position, and then manually render it. That’s something you’d like to avoid if it’s not necessary.

Getting the position of the attachment and applying an offset to it isn’t going to help you one bit. You can’t come up with a solution if you don’t know what the problem is.

Clearly, the problem here comes from the fact that the effect you are using needs an attachment and an entity to compute its position, and there is no way to change that position otherwise. The easiest solution for that is to spawn a clientside entity using ClientsideModel (using any model, doesn’t matter), parent it to your viewmodel, make it invisible, and then use it in muzzleflash:SetEntity. Attachment doesn’t matter since if I remember correctly, no attachment will simply cause the effect to appear in the middle of the entity.

This way you’ve got a way to control your effect and move it around. Once that’s done, all you need to do is modify the position and angles of this invisible entity every time the viewmodel is drawn so it is always located at the muzzle. Of course, getting the position and angle of both muzzles might be problematic as well. It all depends on how you built your viewmodel. Since I’m not familiar with the SWEP creation kit, maybe you could post your entire code on Pastebin or something like that, so I can help you with that part.

Where did I suggest one way, then change it? I’ve been telling him that he can access the position and angle all along from the Attachment table. He could go from there. Then, he still didn’t read my post so I said it again, and again, and then I included that he should make sure he uses the RotateAroundAxis because he’s obviously doesn’t know how to properly access or modify those values; which is why I told him the proper way. You repeating me adds nothing to the thread?

I was talking about your post with the code only. Anyway, just shut up, this isn’t going to help OP.