Aiming CFrame Offset kinda "breaks" the viewmodel animations

Hello guys, I have an issue where my function for calculating aiming offset makes the locked into place, making it impossible for animations like firing to move the gun.

Video Example: 2022 12 14 12 42 07 - YouTube

Does anyone have an idea how I could improve on the code to fix this issue?

local module = function(loadout, offset, scale)
	
	local aimPartData = loadout.aim_part_data;
	
	local aimPartCFrame = aimPartData.aim_part.CFrame;
	local viewmodelCamCFrame = loadout.current.PrimaryPart.CFrame;
	
	local aim_alpha = loadout.tween_values.aim_alpha.Value;
	
	offset = CFrame.identity:Lerp(viewmodelCamCFrame:ToObjectSpace(aimPartCFrame), aim_alpha):Inverse();
	
	return offset;
end;

return module;

Note: removing the Inverse() function at the end fixes the issue of animations not moving the gun, but of course the aiming offset is wrong in that case

Edit: Improved the cframe code a bit

offset_aim = calculateAimOffset(loadout, offset_aim, scale);

loadout.current:SetPrimaryPartCFrame(cam.CFrame * offset_aim);

What’s causing it is because the “aim part” is locked to the camera, so when the weapon moves, the camera moves with it, therefore making it look like the weapon isn’t moving. I’ve had this problem, I wasn’t able to fix it but I cheesed it.

I applied recoil to the camera using Springs which made it give the effect of the gun moving.

I am sorry if this advice doesn’t help too much but I hope it gives you a understanding of why this is happening. Have a good morning (at least for me)

1 Like

I’m gonna look into the springs method since I always wanted to have some kind of dynamic visual recoil, thank you. Hopefully I figure out how to go around this eventually

1 Like

Heyyy, figured it out :stuck_out_tongue:

I basically added a condition check to see if the aim progress value has changed before calculating a new aiming offset.

image

There’s most likely a way better solution that would come from tweaking the viewmodel rig itself, but nu uh :point_up:

1 Like

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