Subscribe
 Post #1
 24th June 2007
mrflippy's Avatar
June 2005
541 Posts
This is a continuation of my old thread.

I'm trying to create a custom flashlight.

I have a SENT that spawns an effect_flashlight at its location. I want this SENT to move with the player's weapon. If I parent it to the weapon, I get bizarre positioning and behavior. (Example screenshot) It looks like this is because the positions are for the world model and not the view model.

If I parent the SENT to the player's view model, things look fantastic in first person. The light looks like it's coming from the barrel of the gun, and it moves correctly. However, if I look at myself from a camera, the light is not visible. I assume this is because the view model doesn't exist outside of first person view.

So, how do I resolve this? I want the light to move correctly in first person view, but also be visible by other players.
 Post #2
 24th June 2007
Gold Member
jA_cOp's Avatar
May 2006
4,833 Posts
mrflippy posted:
This is a continuation of my old thread.

I'm trying to create a custom flashlight.

I have a SENT that spawns an effect_flashlight at its location. I want this SENT to move with the player's weapon. If I parent it to the weapon, I get bizarre positioning and behavior. (Example screenshot) It looks like this is because the positions are for the world model and not the view model.

If I parent the SENT to the player's view model, things look fantastic in first person. The light looks like it's coming from the barrel of the gun, and it moves correctly. However, if I look at myself from a camera, the light is not visible. I assume this is because the view model doesn't exist outside of first person view.

So, how do I resolve this? I want the light to move correctly in first person view, but also be visible by other players.
Did you try positioning it to the ShootPos but with an offset, finely tuning it into position? Not the easy way, but it's worth a try :)
 Post #3
 24th June 2007
mrflippy's Avatar
June 2005
541 Posts
jA_cOp posted:
Did you try positioning it to the ShootPos but with an offset, finely tuning it into position? Not the easy way, but it's worth a try :)
The problem with setting the position manually is that the light lags behind player movement.
 Post #4
 24th June 2007
Gold Member
jA_cOp's Avatar
May 2006
4,833 Posts
mrflippy posted:
The problem with setting the position manually is that the light lags behind player movement.
What? You'd still be parenting it. Am I missing something? :P
 Post #5
 24th June 2007
Gold Member
Gmod4ever's Avatar
August 2005
12,301 Posts
Get shootpos, add ten units on Z scale, parent.

Also, I like this idea. effect_flashlight you say? Maybe I can get it to work for Black Sun. :)
 Post #6
 24th June 2007
mrflippy's Avatar
June 2005
541 Posts
FYI: ShootPos() returns the location of the player's head, not the location of the gun's muzzle.

Still doing some testing with this.
 Post #7
 24th June 2007
Gold Member
Gmod4ever's Avatar
August 2005
12,301 Posts
Player:GetShootPos() returns the muzzle bone of the gun. I'd think.
 Post #8
 24th June 2007
mrflippy's Avatar
June 2005
541 Posts
Gmod4ever posted:
Player:GetShootPos() returns the muzzle bone of the gun. I'd think.
Except that it doesn't :)

In my SWEP think function:
self.Flashlight:SetPos(self.Owner:GetShootPos())

That always puts the flashlight model right on my head.

Edit:

The location of the muzzle is:

self.Weapon:GetAttachment(self.Weapon:LookupAttachment("muzzle")).Pos

(May not work for CS weapons, as they have a different attachment name or something)

Edit: Except that's the location of the world model's muzzle, not the view model's. Even doing

self.Owner:GetViewModel():GetAttachment(self.Owner:GetViewModel():LookupAttachment("muzzle")).Pos
doesn't seem to work quite right for the view model's position.
 Post #9
 24th June 2007
Gold Member
jA_cOp's Avatar
May 2006
4,833 Posts
Gmod4ever posted:
Player:GetShootPos() returns the muzzle bone of the gun. I'd think.
No, returns the position of the clients' screen. The screen is a bit off the head, too :)

edit:

Did you try the attachment for the world model? Maybe it helps.
 Post #10
 24th June 2007
mrflippy's Avatar
June 2005
541 Posts
If I just do a SetParent(owner) without doing anything with attachments, the positioning seems correct, but I can't change the angles. (The light will move side to side with me, but not up and down when I aim)

If I set an attachment to a world model, it looks stupid in first person mode.

Edit: SetAngles doesn't seem to behave how I would expect on parented entities.
 Post #11
 25th June 2007
Gold Member
Gmod4ever's Avatar
August 2005
12,301 Posts
Try setting your light's angles to your view angles, as an angle. Example.

function SWEP:Think()
self.Light:SetAngles(self.Owner:GetAimVector():Angle())
end

With it being parented already, of course.
 Post #12
 25th June 2007
mrflippy's Avatar
June 2005
541 Posts
Gmod4ever posted:
Try setting your light's angles to your view angles, as an angle. Example.

function SWEP:Think()
self.Light:SetAngles(self.Owner:GetAimVector():Angle())
end

With it being parented already, of course.
Yeah, I'm having to add Vector(270,0,0) to get the correct angle or something. Otherwise, the angles are inverted or something crazy.

Edit: And I haven't had any luck getting the vertical angles to work when it's parented.
Reply


All times are GMT. The time now is 05:31PM.

Facepunch Studios 2009 - Server 'Softlayer 2.0'