For some reason, the player character doesn’t rotate the whole way to where the mouse click.
The dot indicates precisely where I tapped.
local script
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
local Mouse = player:GetMouse()
local MouseFunction
MouseFunction = Mouse.Button1Down:Connect(function()
player.Character.PrimaryPart.CFrame = CFrame.new(player.Character.PrimaryPart.Position,Vector3.new(Mouse.hit.Position.X,player.Character.PrimaryPart.Position.Y,Mouse.hit.Position.Z))
MouseFunction:Disconnect()
end)
end)
I’ve tried doing the rotation code in a script but the same thing happen.
edit: if you’re wondering why there’s script.Parent.MouseButton1Down. This is a code that is inside that Ultimatekick Gui. Basically you have to tap/click on it and then tap/click anywhere on the screen to fire it. When you tap/click again, it will get where you click/tap, I made it so the character face that way, but it won’t work.
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, mouse.Hit.Position)
end)
Hang on, lemme try to do it with a click only, without having to click the gui first and then clicking. The thing is, I did it with another thing on touchscreen, it work perfectly fine, the pc version of this also work fine but I just don’t know why this one won’t work.
aight, so I found out that after testing, no matter where your cam face and no mater where you click it faces slightly to the right, you can probs notice that in the vid(happened all the time when I tested)
You shouldn’t use the mouse object as it has been superseded by UserInputService and likely will be deprecated soon. You could use workspace.CurrentCamera:ScreenPointToRay() with the player’s 2D tap/mouse position. Then, you could use a raycast using the unit ray it returns and make the player face the raycast’s hit position.
(for pc, you could use something like TouchTapInWorld for mobile)
ex:
--add other variables like "character", etc.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local location = UserInputService:GetMouseLocation()
local unitRay = workspace.CurrentCamera:ScreenPointToRay(location.X, location.Y)
local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 10000) -- you could add raycast params if you want
character.PrimaryPart.CFrame = CFrame.lookAt(character.PrimaryPart.Position, raycastResult.Position)
end
end)
edit: fixed something idk if it changes anything though.