What do you want to achieve?
I want to make it so that when the player moves their camera, their gun will slightly follow the direction the camera was moving in, for example, the player moves their camera to the right so the gun points slightly to the right.
What is the issue? Include screenshots / videos if possible!
There is no issue, I just wanted to know how I could perform this, simply to make my game look better. I apologise if I have posted to the wrong category, this is my first post.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’m quite a newbie scripter, so I didn’t really know what to do. I didn’t find anything about this on the Developer Hub, but if you did and I have missed it, I am sorry. I did make a Reddit post but it only got 1 comment and I didn’t really understand.
You may see this in games like Deadline. I was wondering how I could achieve this? I am not asking for a script, I just would like to be guided on how this could work so I learn something and can recreate it myself.
One somewhat hacky but simple way is just repeatedly lerping the camera to where it should be within a RunService event, it will probably look like it’s basically instant since it’s tied to FPS.
alternatively, if you wanna have more freedom for extra stuff, get the movement of the camera and offset the viewmodel towards the opposite direction, and also go reducing the offset, so it slowly returns back to the center
you can make your viewmodels cframe to the cameras cframe with a offset
here’s a example of how you would do this.
also I would recommend adding some kind of bobbing effect to your viewmodel to make it feel more realistic you can do that using sin waves and cosine waves
unless you dont want that effect.
you can also give your viewmodel animations by adding a animationcontroller and animator to your viewmodel
make sure you have a offset or the viewmodel wont be visible to the player
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local offset = CFrame.new(2, 1, 0.8)
local viewmodel = workspace:WaitForChild("ViewModel")
-- assuming your viewmodel is a model you would use the PivotTo() method
local connection = RunService.RenderStepped:Connect(function()
local cf = camera.CFrame * offset
viewmodel.CFrame:PivotTo(cf)
end
rotate the gun on the by userInputService:GetMouseDelta(), probably use tweens or spring modules to make it smooth
the way deadline has it, the gun doesn’t return to the center, so they’re using the mouseDelta to change a clamped variable
here’s a little tiny demo if you want to look at it gundirection.rbxl (56.6 KB)
I’m sorry if I am incorrect but I think a lot of you have misunderstood me. I am not askint how to make a viewmodel. I already have viewmodel and working FPS system. I am simply asking how I could get the viewmodel, that is already working, to move slightly to where the player turns their camera before they actually turn around. I am unable to right now but I will try to provide videos to help you understand. Thank you to all the people who commented and attempted to help me.
I appreciate your help I have now learned about Mouse Delta thanks to you and will experiment with it more. The demo script is broken by the way
Edit: Don’t worry, I got the demo working and now I can see what Mouse Delta does. This is exactly what I’m looking for Thank you so much. If you’re wondering what was wrong with the script, it was just getting confused because there was no exact primary part.