• How to attach first person camera to a bone?
    15 replies, posted
I have a weapon mod with many custom camera animations and i wonder if its possible to make the first person camera follow its bone rotations and positions.
You could change the view origin and angles to that of the viewmodel attachment/bones, BUT as far as I remember, there is a bug that prevents this from working because of wrong pos/angles returned in certain hooks required for that
Heres the code i used: local function CalcView( pl, pos, angles, fov ) local view = {} local wp = pl:GetViewModel(0) if IsValid(wp) then if pl:GetActiveWeapon():GetClass() == "mccree_peacekeeper" then local BonePos = pl:GetActiveWeapon():LookupBone("BONE_005F0") view.origin = pl:GetActiveWeapon():GetBonePosition(BonePos).Pos view.angles = wp:GetAttachment(wp:LookupAttachment("attach_camera")).Ang view.fov = fov return view end end end The camera follows the attachment angles just perfectly, but the problem is with the position. I tried with the same attachment but it was returning the center of the world, so my camera was far away from my body. With the GetBonePositions.Pos the camera is rightly set to the bone (almost) but theres another problem, when i normaly aim towards any direction, the camera is still stuck at that orientation, its like when you press C and go to change your Player model, the viewmodel model follows your mouse instead of just stay frozen as normally.
Just an observation, you are using the angles from the View model, but the position from the World model, is that correct or did you want both position and angle from the View model? As for the second problem, I don't understand, try making a video or something.
It was an misanderstanding of the value that GetBonePosition returns which is omething that its not usefull here, sorry. So like i said, by only using the angles of the attachment, the camera was doing the moves i made for the bone just fine, then when i used the position of the attachment, the camera was set to where it should be but it was frozen to the left, i mean it wasn't following my mouse at all. The wierd thing is that when i just disconnected and opened another map, i didnt changed a bit of my code and anyways this bug started happening: Using view model attachments for cameras causes them to spaz the.. I just wonder why it wasnt happening when i first tried with the code above (ignoring the part of BonePosition).
Yep that is what I am talking about. You cannot get the proper attachment pos/angles from CalcView, I tried to do thing like this before and the results were horrible. Unless we can get a fix on this, I can't think of a way to do it.
You'd be surprised if i say that i got it working... well half of it. If i use CalcViewModelView instead of CalcView, do i get better results? i really dont know what is the diference between both.
The former is the position and angle of the viewmodel parented to the player. That is the actual weapon you see. Changing position and angles here will let you modify the gun angle and position without changing what the player sees ( this is probably what you want to use for a high noon ability ) The latter is the position and angle of the player's "camera". That is the view that a player sees when he's walking around. Changing position and angles here will let you modify what the player is looking at on their screen. Third person cameras use this to pull back the view of the player above their model.
Ok so here is how i got it working. Before i started recording, that world view was flickering on my screen very hard, then when i started recording the world view just freezed like that. As you see, slowing the time, which i think that slows all update rates, you can see that the view model camera is rightly following McCree's camera bone animations in every single one of them. Why the other world view is tring to get over my view model view is what i have to discover. (i dunno why the quality is so terrify, i just rendered as sony vegas standard mp4 template) https://files.facepunch.com/forum/upload/185744/9f5d22ef-4f76-4abb-a588-4bf341cc621a/Untitled.mp4
Yep, that code is exactly the right code supposed to make it work, but the bug is that in CalcView, using viewmodel attachment pos/ang does not work properly. There is nothing you can do, you are going to have to wait for a fix. Strangely, I might be wrong, but I remember that this used to work back in the day, not sure at what point it got broken.
Well this is just sad then. Anyway i have a lot of things to do on this mod so i can try it again later if the next update brings the fix. Btw this is what i got for Dead Eye so far. By just changing the viewmodel position would look bad because the hat would move too. Do you have any ideas of how to make both arms look to my target? I tried BuildBonePositions and SetBonePositions and ManipulateBonePosition but i think i coded all of them wrong. https://files.facepunch.com/forum/upload/185744/627badb3-2d2d-4125-bc00-28d8e32a2047/temp.wmv
Update, I was experimenting with camera attachments again and I got it working: gmod_vm_camera_att_view The trick is you have to store the attachment angle somewhere, and in the next frame subtract it from the current attachment angle, and then add the player:EyeAngles() Works in both GM:CalcView() and SWEP:CalcView(), position and angle, bones and attachments, you just have to modify it for GM:CalcView since it returns a CamData structure.
Oh thats really wonderful news. I'm gonna give it a try then ill report the results.
Sorry for bumping the thread but i got it working with angles as you proposed and wanted to report. Now i only need to work with the attachment position which has the same "issue". Do you have any ideas?
Do the same thing, store the position in a variable after setting it to the view and then subtract it from the viewdata.pos on the next frame. I also found out that using Lerp on the pos/ang values seems to make them work correctly
Sorry for my ignorance but what exactly is this Lerp you mentioned?
Sorry, you need to Log In to post a reply to this thread.