Gun sight problem

I have a problem with my player aiming system


	local camera = workspace.Camera 
	
	local tween_service = game:GetService("TweenService") 
	local tween_info = TweenInfo.new(0.03, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true) 
	
	tween_service:Create(camera, tween_info, {CFrame = camera.CFrame * CFrame.new(0, 0.5, 0)}):Play() 
end)

but when the player moves, the camera has a certain problem
robloxapp-20230315-1806312.wmv (1.1 MB)
This is how it works when the player is stationary:
robloxapp-20230315-1806011.wmv (919.5 KB)

and that happens because it is programmed to change the CFrame of the weapon and that is why when it runs it stays in that CFrame and the script waits for the animation to end to return to the proper CFrame…
What I want:
It is that although the player runs when the CFrame changes, it follows the player when it runs, what happens is that I don’t know how to do it. If you can send me a tutorial or anything, I would appreciate it very much.
basically in case you didn’t understand which of the videos is the example of how I want the weapon is when the player is stopped

2 Likes

I hope for someone’s help. The truth is this forum is lonely or maybe selfish, I don’t know.

2 Likes

I really hoped someone would help but well what else can I do?

2 Likes

You can try lerping, but the Tween method seems good enough.

1 Like

what is lerping? bro I’m sorry I know I’ve been bothered a lot but I’ve only been working with these things for 5 days and I really feel the pressure. The Tween method is very good, thanks for that…
but the only problem is the CFrame since it adjusts to an Exact position therefore if the player moves the camera will look a little behind

1 Like

idk too, but tweening is a good method, it might be a problem with the CFrame calculations

1 Like

The CFrame is correct but would you know a documentation that I can see about it or would not use LookVector work?

local camera = workspace.Camera 
	
	local tween_service = game:GetService("TweenService") 
	local tween_info = TweenInfo.new(0.03, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true) 
	
	tween_service:Create(camera, tween_info, {CFrame = camera.LookVector * Vector3.new(0,0.5,0)}):Play() 
end)

@hasoco do you think it works?

1 Like

There’s a guide about it somewhere in the Documentation about changin the Camera’s position to a shoulder camera (can be customised) give me an moment and I’ll link it

(Go to the Over-The-Shoulder section)

If you need an explanation of how the code works I’ll be half of explaining it :blush:

Hey, did you know how to change the rotation instead of the position with TweenService?

1 Like

Simply change:

{CFrame = camera.CFrame * CFrame.new(0, 0.5, 0)}

To:

{Orientation = (whatever type of orientation you need)}