How to offset animations with rotation?

I would like to make a knife system where the animations have motion when the player moves their mouse towards the floor or ceiling. For example, when pointing at the floor, the knife goes down a little, and vice versa for the ceiling.

A good example is featured in the game KAT:

My question is, how would I apply an offset (a rotational CFrame) to a standard roblox animation? I know how to get the angle offset from mouse position and all that, I just am unsure on how to actually apply a CFrame offset to both arms for the weapon animations.

Thanks.

Simple answer: It is not an animation. It is just the knife equipped by the player with no animation that moves about when the player moves his/her mouse.

Edit: From the video you posted, I am sure that the arm is moving, and that is fairly easy to do.

1 Like

Motor6D instance when animating tools.

1 Like

I have done something similar in the past and here’s the code for it

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ToolEquipped = false

local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local RightShoulder = Character:FindFirstChild("RightShoulder", true)
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = RightShoulder.C0.Y
local YOffset3 =  Neck.C0.Y

local Tool = nil
Character.ChildAdded:Connect(function(Child)
	if Child:IsA("Tool") then
		ToolEquipped = true
		Tool = Child
	end
end)
Character.ChildRemoved:Connect(function(Child)
	if Child == Tool then
		Tool = nil
		ToolEquipped = false
	end
end)


game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = Root.CFrame:toObjectSpace(Mouse.Hit).lookVector
	if RightShoulder then
		local Offset = CFrame.Angles(math.rad(90), 0, 0)
		if ToolEquipped == true then
			Offset = CFrame.Angles(math.rad(0), 0, 0)
		else
			Offset = CFrame.Angles(math.rad(90), 0, 0)
		end
		Neck.C0 = CFrame.new(0, YOffset3, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0)
		RightShoulder.C0 = CFrame.new(1, YOffset, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0) * Offset
	end
end)

edit the code as much as you want!

1 Like

How do you replicate the movement if it’s not an animation?

This post isn’t exactly what you’re looking for; In fact, it’s quite different than what you want, but if you first make the object (in this case, the arm models) follow the cursor, you could then try to “freeze” the arms in a position where they can only rotate in the direction the cursor moves, rather than actually have the arms leap off the character and follow the cursor.

As you know, I’m not a programmer, so I can’t give you the logistics, however, if you can figure out what I’m trying to explain, you may be able to get the outcome you want.

I’ve discovered that I would need to recreate the animations using CFrame, which is not really what I was hoping for. I will just not end up adding it to my game. Thanks for everyone’s response.

1 Like

Oh, I see. Sorry I couldn’t have been of more assistance.

Good luck with the game!

1 Like