Character's body look where you click

i want wen i click my character look to where i click like in other games with third person shooter opitions, i tried use look cframe but without sucess, anyone know how i can do this?

1 Like

You said you already tried something but failed.

Could you share the code you had before so we can see what was wrong?

player.Character.HumanoidRootPart.Cframe.Orientation = CFrame.new(Vector3.new(position,0,position)).LookVector

this is the part then fails

I realized that what I wrote probably won’t work for your use case.

May I ask what the position variable is?

what i wrote before Correct me if I'm wrong, but aren't all members of CFrame immutable? Also Cframe is misspelt.

Try this instead:

player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, Vector3.new(position,0,position))

Also, previously you used CFrame.new(Vector3.new(position,0,position)).LookVector but that creates a CFrame with no look vector, so it would always return the same thing.

The updated code I provided will position the HumanoidRootPart to look towards the vector at the (position, 0, position)

the position is the mouse hit position, i need the humanoid cframe look to the mouse hit position

Ah, but position is a vector2, right? Or is it the 3d position of the point where the mouse clicked

its a vector3, the mouse click in the word location

This will get your mouse position and incorporate it to the players current CFrame using the players most important part, their HumanoidRootPart. If you change that CFrame you change the rest of it. If you want them to look up and down as well towards where the mouse clicked then simply change the y value in vector3.new to MousePos.Y.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local HumRoot = Character:WaitForChild("HumanoidRootPart")
Tool.Activated:Connect(function() -- when you click with your tool
  local Mouse = Player:GetMouse()
  local MousePos =  Mouse.Hit.Position
  HumRoot.CFrame = CFrame.new(HumRoot.CFrame, Vector3.new(MousePos.X, HumRoot.CFrame.Y, MousePos.Z))
end)

mouse UDim is vector 2 but it mouse hit position which is what he wants is vector 3.

Edit: Looks like Marshmallowcreator beat me to it.

Ah good, try the following:

local char = player.Character
local hrp = char.HumanoidRootPart
local hpos = hrp.Position
hrp.CFrame = CFrame.new(hpos, Vector3.new(position.X,hpos.Y,position.Z))

Pay attention to hpos and position.

DISCLAIMER: Untested

You forget to grab the mouse position

OP mentioned that ‘position’ is already the mouse 3d world position.

Ah gotcha I misread that my bad.


bruh

apologies replace the HumRoot.CFrame.Y with HumRootPart.Position.Y

HumRoot.CFrame = CFrame.new(HumRoot.CFrame, Vector3.new(MousePos.X, HumRoot.Position.Y, MousePos.Z)) 

same error bro, i realy dont know what is happening

Try replacing it that last line with this.

HumRoot.CFrame = CFrame.new(HumRoot.CFrame * CFrame.new(0,0,0)).p,MousePos) 

You’ve still got an error. The first argument should be the position.

HumRoot.CFrame = CFrame.new(HumRoot.Position, Vector3.new(MousePos.X, HumRoot.Position.Y, MousePos.Z))

@Rexnet_exec

1 Like

works thank you so much bro <3

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