Smooth ADS animation without making animations for every single gun

Soooooo

i really really REALLY want to make some cool ADS animations without actually using animations
now, how do you animate without animations?

cframes! specifically, lerping! (or something similar)

ohhhh but notsad… you absolute stupid silly buffon, you just answered your own question!

i know i need to use cframes, but i don’t know how to get the position i need to use for each gun

should i have an invisible part called “aimpart” and lerp that, but even then, where should i lerp it so it’s on the center of the screen while not covering everything up

how do i make the viewmodel arms “rotate” towards the gun but stay on their current cframe? (if that makes sense)

this is a real hassle for a cframe loser like me to do,
i did ask @awry_y (please see this i need you rn :sob: ) for help at one point

the help i got was… very vague, but not really

i needed toooo calculate an offset?
i think it was something to do with aimPart.CFrame - targetPart.CFrame

so sure, maybe i can just lerp the gun to the result of that subtraction
but what about the viewmodel arms? how do i uh

okay let me draw

does this showcase the main problem? i think so

2 Likes

@awry_y

here’s some help pinging her

2 Likes

cframe the part all the gun parts attach to ez

1 Like

Later.

2 Likes

Best way to do it is to check when the player holds down their right mouse button and then just adjust the ViewModel CFrame. For the ViewModel make two arms and then have them joined to a root part, you can also use PivotTo to achieve this and some Lerping. For my guns I have a attachment called aim, I just get its world CFrame and then move the ViewModel CFrame in relative to that.

I use this code here to get the ADS effect, I would also use lerping so that it looks smoother.

viewModel.Gun.PrimaryPart.Aim.WorldCFrame:ToObjectSpace(viewModel.PrimaryPart.CFrame)
1 Like

You should mention that your code won’t work if the code is ran inside a loop.

To OP:

I did tell you about this previously and I’ll say it again.

You need to figure out an offset for your animation. To do this, you just run this line of code:

print(Camera.CFrame:ToObjectSpace(CFrame.new(AimPart.WorldPosition)).Position)

This returns the offset. Then you can copy that offset and apply it to the viewmodel like so:

local ViewModel = -- your viewmodel.
local aimOffset = CFrame.new(X,Y,Z)

RunService.RenderStepped:Connect(function()
ViewModel:PivotTo(Camera.CFrame*aimOffset)
end)
2 Likes

MY GOAT

so thats how i lerp the viewmodel right??

but what about the arms obstructing the camera, how do i deal with that

1 Like

Show me a video for that.

1 Like

damn i just got up and did that offset thing you wanted me to do

i don’t think this is quite the result we were expecting

not sure what i did wrong? i multiplied by the offset and all that

local function AimGun(weapon: Tool, viewmodel: Model)
	local viewmodelHandle: BasePart = viewmodel:FindFirstChild("Handle")
	local viewmodelAimPart: BasePart = viewmodelHandle:FindFirstChild("AimPart")
	
	-- get initial viewmodel pivot
	local initialPivot = viewmodel:GetPivot()
	
	-- calculate the offset
	local offset = camera.CFrame:ToObjectSpace(CFrame.new(viewmodelAimPart.Position)).Position
	print(offset)
	
	-- pivot the viewmodel (change to lerping later)
	rService:BindToRenderStep("AimGun", Enum.RenderPriority.Camera.Value, function()
		viewmodel:PivotTo(camera.CFrame * CFrame.new(offset))
	end)
	
	-- setup a connection to stop the ADS
	local adsReleasedConn: RBXScriptConnection
	
	adsReleasedConn = mouse.Button2Up:Connect(function()
		-- unbind from renderstep, reset viewmodel position and disconnect
		rService:UnbindFromRenderStep("AimGun")
		viewmodel:PivotTo(initialPivot)
		
		adsReleasedConn:Disconnect()
	end)
end
1 Like

oh i just had to do

viewmodel:PivotTo(camera.CFrame * CFrame.new(-offset))

instead of

viewmodel:PivotTo(camera.CFrame * CFrame.new(offset))

the main problem is solved
now i just need to improve this a bit so it’s not running on hopes and prayers

thansk awyr!!!
:blue_heart:

1 Like

The sign of values matter.

Do note that this means that you would have to update the offset values most of the time to match the new animation.

I would also recommend having the offset set manually by copying the value and putting it in another variable so you can lerp it.

Something like:

Offset here.

Loop stuff
Using the offset.
End
2 Likes

dw vro i know what i’m doing
i’m not THAT bad at lerping i’m just bad at cframes :pensive:

1 Like

You’re bad at a lot of things.

For instance:

local adsReleasedConn: RBXScriptConnection

adsReleasedConn = mouse.Button2Up:Connect(function()
	-- unbind from renderstep, reset viewmodel position and disconnect
	rService:UnbindFromRenderStep("AimGun")
	viewmodel:PivotTo(initialPivot)
	
	adsReleasedConn:Disconnect()
end)

Inefficient method. Use:

mouse.Button2Up:Once(function()
	-- unbind from renderstep, reset viewmodel position and disconnect
	rService:UnbindFromRenderStep("AimGun")
	viewmodel:PivotTo(initialPivot)
end)
1 Like

okay in my defense i never used :Once() and never considered its existence

Dude use my code in a runservice loop it will work

1 Like

???

i’m already doing that

1 Like

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