Videoed here, in Blood Engine, is exactly what I’m looking to achieve:
Take a peek at how the camera orientates itself relative to the gun when equipping and reloading, and simultaneously how the crosshair does the inverse to maintain its position. I can likely figure out one from the other, but I’m not sure how to work out the math to even start. I thought it’d maybe be something like:
- Get the position of the camera
- Get the position of the gun’s Handle
- Calculate a halfway position point between the camera and the gun
- Smoothly lerp the camera’s CFrame angles toward said point
- Rinse and repeat each frame with RenderStepped
Just after writing the above down, I gained some confidence to try on my own and got this so far (a lot of the code is purged of course):
local function camReload()
local halfwayPoint = Camera.CFrame.Position:Lerp(VMTool.Handle.Position, 0.2)
local targetCF = CFrame.lookAt(Camera.CFrame.p, halfwayPoint)
Camera.CFrame = Camera.CFrame:Lerp(targetCF, 0.1)
end
RunService.RenderStepped:Connect(function()
if reloading then
camReload()
end
end)
I think this code has a recursive effect, leading to nauseating camera spinning during testing. I’m assuming its because I’m not manipulating off the base camera CFrame each time, however I’m not even sure how to get this. Whereas you can predict easily the position something like a crosshair GUI will be, the player’s camera CFrame is ever-changing as they look around. It’s not pictured in this code, but I had tried a solution where I get the camera CFrame, subtract whatever changes I made to it the previous frame in hopes of getting back what the base CFrame should be and then going from there, though it didn’t seem to work and ended up giving my camera a seizure.
I’ll likely work more on this, but in the meantime I’d love for someone to lend a hand, particularly towards a solution to avoid the recursiveness. Thanks!
Old edit, irrelevant now
Edit 1:
Little bit of a realization. While the above code still has a recursive effect and causes its own issue, much of the camera spinning was caused by a different recursive issue. Since I’m using a view-model, I have to set the CFrame of the view-model to the camera every frame. This is an issue when reloading because when the camera moves to follow the gun, the view-model (including the gun) will follow it, and then the camera will follow the gun again next frame, and it ends up in a kind of chase.
I disabled this temporarily when reloading, and I’ll have to come back around to fix it, but it also highlights the issue with the other camera manipulation code:
Again, I think this can be fixed if I find out a way to get the “base” CFrame of the camera, but until then the code basically restricts your camera to look at the gun until the reloading is finished.