Rotating character to mouse is not working right

  1. What do you want to achieve? Keep it simple and clear!
    I am making a top down shooter game and I’m trying to make it so that the character will rotate to the direction the mouse is pointing at

  2. What is the issue? Include screenshots / videos if possible!
    It kinda works but it have a problem where the character sinks to the ground for some reason

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried searching but still find no solution

	script.Parent:SetPrimaryPartCFrame(,, script.Parent.HumanoidRootPart.CFrame.Position.Y, game.Players.LocalPlayer:GetMouse().Hit.Position.Z)))
1 Like

Try this out:

local PS = game:GetService("Players")
local RNS = game:GetService("RunService")

local player = PS.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local HRP = char:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()

	HRP.CFrame = CFrame.lookAt(HRP.Position,, HRP.Position.Y, mouse.Hit.Position.Z))

local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()

local function OnRenderStep()
	local Pivot = Character:GetPivot()
	Character:PivotTo(CFrame.lookAt(Pivot.Position,, Pivot.Y, Mouse.Hit.Z)))

1 Like