How to tween a viewmodel in renderstepped?

  1. What do you want to achieve?
    I want to tween my gun viewmodel so that the aimpart lines up with the camera so that my gun will be aimed down sights

  2. What is the issue?
    I don’t want to use animations to do this, and I have tried tweening the position of the viewmodel while aligning it in renderstepped but it either doesn’t work at all or just moves the model instantly instead of tweening it

  3. What solutions have you tried so far?
    basically everything on the devforum I could find

this is the renderstepped in my viewmodel module

RunService.RenderStepped:Connect(function(dt)
	if currentViewmodel then
		local Delta = game.UserInputService:GetMouseDelta()
		local UpdatedSway = SwaySpring:update(dt)
		local UpdatedBob = BobSpring:update(dt)
		
		if not isAiming then
			BobSpring:shove(Vector3.new(Bob(5), Bob(10), Bob(5)) / 10 * (Character.PrimaryPart.Velocity.Magnitude) / 10)
		else
			BobSpring:shove(Vector3.new(Bob(5), Bob(10), Bob(5)) / 100 * (Character.PrimaryPart.Velocity.Magnitude) / 10)
		end
		SwaySpring:shove(Vector3.new(-Delta.X/500, Delta.Y/500, 0))
		
		--somehow tween gun
		currentViewmodel:PivotTo(
			workspace.CurrentCamera.CFrame *
				CFrame.new(UpdatedSway.X, UpdatedSway.Y, 0) *
				CFrame.new(UpdatedBob.X, UpdatedBob.Y, 0)
		)
	end
end)

RenderStepped fires prior to every frame being rendered, so there’s an event every frame, unless you make it so it doesn’t try to tween when it’s already doing so it’s gonna try to tween every single frame

1 Like

I know, I was thinking like how in Unity you can create a tween and every frame tween it a little more because if I just create a tween with the viewmodel, it will tween to where the camera was at that time, so it kind of detaches from the camera

i fixed it by making a number value that tweens between 0 and 1 when you aim in and out, and then lerping the viewmodels position by an offset with that number value as the alpha

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.