Okay so I haven't made a game or used roblox studio in a while but I chose to do it once again a couple days ago. I chose to make a character for the game but not using any of the built in roblox things for a character so I could really do whatever I wanted with it. I have the controls down, but I just need for my character to be able to rotate with my mouse when I move it left, or right. How would I do that?
How can I move my character left and right with the mouse?
1 answer
This would be some hefty work, so I did what every other programmer would've done: pulled a script from online.
Here is the webpage in which I found the code you were looking for. I did some minor edits; I hope this works for you!
--###----------[[SERVICES]]----------###--
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
--###----------[[VARIABLES]]----------###--
local Player = Players.LocalPlayer
local Character = Player.Character
local CharacterRoot = Character.PrimaryPart
local CharacterHead = Player.Character.Head
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()
--###----------[[FUNCTIONS]]----------###--
local function GetPlaneIntersectionPointFromRay(PlanePoint, PlaneNormal, RayOrigin, RayDirection)
return (RayDirection * -((RayOrigin - PlanePoint):Dot(PlaneNormal) / RayDirection:Dot(PlaneNormal))) + RayOrigin
end
--###----------[[SETUP]]----------###--
local BodyGyro = Instance.new("BodyGyro")
---------------
BodyGyro.D = 40
BodyGyro.P = 10000
BodyGyro.MaxTorque = Vector3.new(4e6, 4e6, 4e6)
---------------
BodyGyro.Name = "CursorPivot"
BodyGyro.Parent = CharacterRoot
--###----------[[INSTRUCTIONS]]----------###--
while (CharacterRoot.CursorPivot) do
---------------
local Raycast = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)
local PlaneNormal = Vector3.new(0, 1, 0)
---------------
local PlaneIntersectionPoint = GetPlaneIntersectionPointFromRay(CharacterHead.Position, PlaneNormal, Raycast.Origin, Raycast.Direction)
---------------
BodyGyro.CFrame = CFrame.new(
---------------
CharacterRoot.Position,
---------------
Vector3.new(PlaneIntersectionPoint.X, CharacterRoot.Position.Y, PlaneIntersectionPoint.Z)
)
---------------
RunService.Heartbeat:Wait()
end
5 comments
Thank you very much. I would of never come up with this. I will look deep into it tonight on my phone and will try it tomorrow. Thank you very much kind sir.
But where do you even originally learn this stuff?
It's not necessarily a practice alone. As it is with programming in general, you have to accumulate experience and intellect to establish the route to completing your goal, and the steps involved.
In this case, you'd begin by deducing the rudimentary details: Rotate a body -> BodyGryo, Fix to the Cursor -> Mouse (Determine the specifics in pinpointing it's landing point in a physical space—begin involving physics calculations)
If you build your ability in determining the elements used in the program you seek (the steps required to achieve your task) you can easily begin building complex projects before you know it; even if you lack the intellect to achieve it by your lonesome, you have the necessary materials for research
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Define move.
I mean to rotate when I move the mouse just like the shift lock switch thing you can do