hello!
I am making a character movement system for my game and I want players only to rotate in 0,90,0 or 0,-90,0 depending on the mouse position.
How do I make it?
hello!
I am making a character movement system for my game and I want players only to rotate in 0,90,0 or 0,-90,0 depending on the mouse position.
How do I make it?
Try:
local RunService = game:GetService("RunService")
local function rayPlate(OriginalPos, Origin, Direction)
return -((Origin-OriginalPos):Dot(Vector3.new(0, 1, 0)))/(Direction:Dot(Vector3.new(0, 1, 0)))
end
local GetMouseVector = function()
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local unitRayDirection = Camera:ScreenPointToRay(Mouse.X,Mouse.Y)
return unitRayDirection
end
RunService.Heartbeat:Connect(function()
local MouseRay = GetMouseVector()
local GettedVector = MouseRay.Direction*rayPlate(Player.Character.Head.Position, MouseRay.Origin, MouseRay.Direction) + MouseRay.Origin
HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.Position,Vector3.new(GettedVector.X,HumanoidRootPart.Position.Y,GettedVector.Z))
end)
It could be smoother:
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local function rayPlate(OriginalPos, Origin, Direction)
return -((Origin-OriginalPos):Dot(Vector3.new(0, 1, 0)))/(Direction:Dot(Vector3.new(0, 1, 0)))
end
local GetMouseVector = function()
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local unitRayDirection = Camera:ScreenPointToRay(Mouse.X,Mouse.Y)
return unitRayDirection
end
RunService.Heartbeat:Connect(function()
local MouseRay = GetMouseVector()
local GettedVector = MouseRay.Direction*rayPlate(Player.Character.Head.Position, MouseRay.Origin, MouseRay.Direction) + MouseRay.Origin
--HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.Position,Vector3.new(GettedVector.X,HumanoidRootPart.Position.Y,GettedVector.Z))
local tween2 = TweenService:Create(HumanoidRootPart, TweenInfo.new(0.35,Enum.EasingStyle.Linear), {CFrame = CFrame.lookAt(HumanoidRootPart.Position,Vector3.new(GettedVector.X,HumanoidRootPart.Position.Y,GettedVector.Z))})
tween2:Play()
end)
I’m sorry for replying after some days.
But your script doesn’t work for me
Can you tell where I gonna put it?
Hello again!
Although your script isn’t working for me, I am still really grateful for your support.
I will give you a solution!
Thank you so so much!
Hello again and again
After looking at your script, I have made a new one base on your script, and it works! It actually very simple and I can make it myself if I know what CFrame.Lookat does and how to use it.
Thank you again, you are a big help to me.
I don’t understand why it doesn’t work for you, here is an example of using the script:
MouseRotation.rbxl (36.3 KB)
oh, ok(did not notice the message)