Trying to make HumanoidRootPart aim at Cursor

I am trying to make it where if you shift lock the wave aims wherever your aiming

The wave is teleporting you whenever you shift lock I know it is probably because the CFrame counts for position too but I cannot find a way to make it only count for direction

I tried using raycast and other stuff that I am blanking out on

local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")

local cHandler = require(RS:WaitForChild("Universal Handler"))

local kHHandler = RS:WaitForChild("Kamehameha Handler")

local kHWave = game.Workspace:WaitForChild("Kamehameha Wave")

local WaveTween;

kHHandler.OnServerInvoke = function(player, abilityID, isShiftLock, mouseCFrame, cameraPos)
	print("release")
	print(isShiftLock)
	local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
	humanoidRootPart.Anchored = true
	local rootPartRotation =  humanoidRootPart.CFrame * CFrame.Angles(0, math.rad(180), 0)
	local waveClone = kHWave:Clone()
	if humanoidRootPart == nil then
		error("Cannot find Humanoid Root Part")
		return
	end
	
	local cFrameLookAt = CFrame.lookAt(Vector3.new(mouseCFrame.X, mouseCFrame.Y, mouseCFrame.Z), Vector3.yAxis)
	
	if isShiftLock == true then
		humanoidRootPart.CFrame = cFrameLookAt
	end
	waveClone:PivotTo(humanoidRootPart.CFrame * CFrame.new(0,-15,-3.5))
	--[[ you cannot subtract or add cframes can only multiply and divide(I think divide idk)]]
	waveClone.Parent = game.Workspace

	for num,child in waveClone:GetChildren() do

		child.Name = "Wave"
		child.CanCollide = false
		child.Rotation = player.Character:WaitForChild("HumanoidRootPart").Rotation + Vector3.new(0,90,0)
		WaveTween = TS:Create(child,TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out), 
			{Size = Vector3.new(child.Size.X + 160,child.Size.Y,child.Size.Z), CFrame = child.CFrame + humanoidRootPart.CFrame.LookVector * 80})
		WaveTween:Play()
		WaveTween.Completed:Connect(function()

			child:Destroy()
			humanoidRootPart.Anchored = false
		end)
	end	
end

Quick studio test script..

--LocalScript
local rs=game:GetService("RunService")
local plr=game.Players.LocalPlayer
local char=plr.Character or plr.CharacterAdded:Wait()
local hrp=char:WaitForChild("HumanoidRootPart")
local mouse=plr:GetMouse()
local pos=nil

rs.RenderStepped:Connect(function() pos=mouse.Hit.Position
	hrp.CFrame=CFrame.lookAt(hrp.Position,Vector3.new(pos.X,hrp.Position.Y,pos.Z))
end)
1 Like

Thank you, it did not work but I realized I misunderstood how to use CFrame.LookAt and that it would be easy for other abilities if I had it checking for it always when shiftlocked not just when using the ability.
to be clear it did fix the humanoidrootpart issue but only locally so I will try to fix that and I will post the fix when I do

Thought it would take longer to fix the locale issue
What I did was do everything you/2112Jay said and made the HumanoidRootPart CFrame one of the thingmajigs that get carry over to the server script
Thanks for the help

I could have also probably just carried over the variables

I have a “gun” that is like this, it turns to face the mouse then fires..

MousePos=mouse.Hit.p
local RootPos=Root.Position --Root here is set to HumanoidRootPart
local direction=(MousePos-RootPos).unit
local angle=math.atan2(direction.X,direction.Z)
local tweenInfo=TweenInfo.new(0.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
local rotateTween=game:GetService"TweenService":Create(Root,tweenInfo,{
	CFrame=CFrame.new(RootPos)*CFrame.Angles(0,math.pi+angle,0)}) rotateTween:Play()

This is a chunk out of that script. I remember this being a bit hard to get right.

1 Like

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