Setting UpperTorso's CFrame equal to the Mouse's position

I wrote a script which is supposed to change the CFrame of the Upper Torso of a player when the player equips a gun equal to the Mouse’s position.

Script

However there are two problems:

  1. The CFrame only changes temporarily, like I want it to always equal to the Position of the mouse until the gun is un equipped.

  2. I want to some how add inverse kinematics.

1 Like

Still not fixed. If anyone know’s a solution please let me know.

local player = game.Players.LocalPlayer
local character = player.Character

if not character or not character.Parent then
    character = player.CharacterAdded:wait()
	tor = character:WaitForChild("UpperTorso").Waist
	hum = character:WaitForChild("Humanoid")
end

local cam = game.Workspace.CurrentCamera
local equipped = false
local waist
local hum

player.CharacterAdded:Connect(function()
	character = player.Character
	waist = character:WaitForChild("UpperTorso"):WaitForChild("Waist")
	hum = character:WaitForChild("Humanoid")
end)

local Mouse = player:GetMouse()
local prev_mousehit

game:GetService("RunService").RenderStepped:Connect(function()
	if (cam.Focus.p-cam.CoordinateFrame.p).magnitude > 1 then
		hum.AutoRotate = false
		if Mouse.Hit.p ~= prev_mousehit then
			waist.C0 = CFrame.new(waist.C0.p, Vector3.new(Mouse.Hit.p.x,Mouse.Hit.p.y,Mouse.Hit.p.z))
			prev_mousehit = Mouse.Hit.p
		end
	else
		hum.AutoRotate = true
	end
end)
1 Like

Can you please explain this? It would be much appreciated.

I can’t really explain it sorry.

Just this part please. It would be much appreciated.

I can’t really explain how it works exactly

if (cam.Focus.p-cam.CoordinateFrame.p).magnitude > 1 then -- so u dont spin weirdly if u look at ur body ig.

but u should do print(cam.Focus.p , cam.CoordinateFrame.p)
waist.C0 = Rotation Cframe.new(part1position,part2position) example part1position will look to part2position

As much as I can see in the script, he wants to be explained to him:

waist.C0 = CFrame.new(waist.C0.p, Vector3.new(Mouse.Hit.p.x,Mouse.Hit.p.y,Mouse.Hit.p.z))

This line basically does the rotation part, it takes the First position as the waist’s position & the second arguement is the lookAt, so it basically makes the waist look towards the mouse hit Position.

Yup as I said example part1position will look to part2position

1 Like