First Person Gun

What would the best way to have the gun follow the characters camera?

This is what I am currently doing, I am welding the gun to the head and have the head rotate depending on the camera. Heres a gif

3 Likes

Your method seems ample. I personally would do it the same way. There probably are more efficient methods of doing so, but to me this seems fine.

1 Like

That is probably one of the easiest ways in my opinion.

1 Like

The thing is the gun moves away from the camera as you can seei nthe gif it moves away.

Do you mean when the camera is pointed down to the floor? I think (I could be wrong) that is simply a problem with the camera’s occlusion. It doesn’t look as though it’s a massive problem. Though, if you wanted to change the behaviour of the camera’s occlusion, you could use the DevCameraOcclusionMode property.

guncf = cam.CFrame*offset

^ in a rendersteppd

welding to the head is kind of an old outdated method

6 Likes

I’ve not made a FP gun, but this is absolutely what I’d recommend doing, and is what every other FPS does. As a bonus other games force the gun to render on top of everything else so there is never any clipping, but I dont think thats possible in Roblox yet.

1 Like

As far as I know, having the gun render on top of everything else requires two cameras.

A staff member has talked about this before on a feature request and why having a model overlap everything else like guns in first person shooters won’t happen, something about generalizing games I think? Bottom line is it won’t be possible.

Heya Geckoco

I used Attachments to represent camera positions on my gun:

The Pink blocks represent the gun Handle and Handle1 (for rendering a secondary hand - not necessary for you atm)
The gun itself is in a model - with Handle as it’s primary part - then I set the primary part’s cframe to the camera coordinate frame, and applied the offset from which ever attachment was being used.
The benefit with this system is that I can easily move about the camera offsets quickly and accurately.

You can actually use this stuff if you like - I don’t intend making anything out of it.

NOTE - THE GUN SHOOTING SYSTEM IS SEVERELY BROKEN AND LAGS WHEN THERE’S MORE THAN ONE PLAYER - I DON’T RECOMMEND USING IT

2 Likes

Weld model parts together and then use :SetPrimaryPartCframe() in a bindrenderstepped

1 Like

But SetPrimaryPartCFrame after a few times being fired it breaks up the model

What I have done is have the gun follow the camera.

You don’t need to weld if the guns are anchored and non-collidable.

Its onlu when you drop a gun you’d need to worry about that.

@Geckoco Welding them fixes that

@WingItMan Not welding causes it to break apart when using SetPrimaryPartCframe

As I mentioned with my method - my guns are in models and are anchored - which are then parented to the camera, not a Tool object.
This eliminates the annoying bugs and breaking problems you have to solve when using welds (believe me - the amount of times I’ve tried to get welds working is ridiculous - this method is so much simpler and easier to handle).

I’d imagine it would be much more cost effective physically as well - since static (anchored) bricks use less resources.
I could be wrong on that though.

Basically though, its the same method as you’d use for engines like Unity.

If you use SetPrimaryPartCframe they will break apart over time if not welded.