Hello. I’m building a wand system simply put. And i’m having a little trouble with the math of how i would rotate the player in the general direction of the mouse target, whether up, or down, or wherever, but without causing the body to suddenly be positioned up or down if you click in a higher direction or lower direction. I hope that made sense. But if I just change the primarypartcframe of the player’s character, with the mousetargets cframe, it causes the character to face EXACTLY in the direction of the mouse target, instead of just in the general direction. I don’t want the character to fall over.
Any help or advice would be appreciated.
Thanks!
-Manelin
You need a BasePart that welded on torso by Motor6D and the arms should be welded on that basepart, then you can modify the CFrame of Motor6D of the BasePart using Mouse CFrame C0/C1 stuffs.
--Mouse is obviously the mouse. HRP is HumanoidRootPart.
--Try to make it like "LookAtMouse(Mouse.Hit.p, Player.Character.HumanoidRootPart)"
function LookAtMouse(MouseHit, HRP)
local Gyro = Instance.new("BodyGyro", HRP)
Gyro.P = 100000
Gyro.MaxTorque = Vector3.new(0, math.huge, 0)
Gyro.CFrame = CFrame.new(HRP.Position, MouseHit)
end
like that?
I just tested out this. This is local script btw.
function LookAtMouse(MouseHit, HRP)
local Gyro = Instance.new("BodyGyro", HRP)
Gyro.P = 10000
Gyro.MaxTorque = Vector3.new(0, math.huge, 0)
Gyro.CFrame = CFrame.new(HRP.Position, MouseHit)
game:GetService("Debris"):AddItem(Gyro, .1)
end
spawn(function()
wait(.1)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
LookAtMouse(Mouse.Hit.p, Player.Character.HumanoidRootPart)
end)
end)