I want to make the player rotate around a certain position by pressing A and D

I want to do the same as below: pressing A and D moves the camera left to right as well as rotates the golf club around the ball. It’s like welding but the player can still rotate.


apologies for the laggy mess that is gyazo gif

I’m not really sure to start, I had originally thought I could try using rope constraints though they are very glitchy. Thanks for the help.

I think you need to set up a custom camera controller to do this like:

local camera, cameraPart = workspace.CurrentCamera, workspace.CameraPart
local rotation = math.rad(9) 
local curRot = 0
local camUpdate = "camUpdate"
local rs, uis = game:GetService("RunService"), game:GetService("UserInputService")

if LOCK_CAMERA then
   camera.CameraType = "Scriptable"
   rs:BindToRenderStep(camUpdate, Enum.RenderPriority.Camera.Value, function(dt)
      if uis:IsKeyDown(Enum.KeyCode.A) and not uis:IsKeyDown(Enum.KeyCode.D)  then -- ik this is unreliable i think but im trying to help, dont bombard me with corrections ;-;
         curRot += -rotation
      elseif not uis:IsKeyDown(Enum.KeyCode.A) and uis:IsKeyDown(Enum.KeyCode.D)  then
         curRot += rotation
      else
         curRot += 0
      end
      
      camera.CFrame = cameraPart.CFrame * CFrame.Angles(0, curRot, 0)
   end)
else
   camera.CameraType = "Custom"
   rs:UnbindFromRenderStep(camUpdate)
end

Fixed some typos

2 Likes

I would recommend a few of small additions and changes to this very well organized script

Firstly to give the “pivoting” ability, you would want to apply it with some offset and centralized origin
For example:

--rather than camera.CFrame = cameraPart...
camera.CFrame = origin * CFrame.Angles(0,curRot,0) * CFrame.new(0,offsetUp,offsetForwards)

Where origin is the center cframe with the rotation of where you want it to face
You would likely just do this once each time you go into the swinging mode

I would also use a cframe based thing for the character, basically the same thing as the camera but rotated 90 degrees

character.CFrame = origin * CFrame.Angles(0,math.pi/2+curRot,0) * CFrame.new(0,offsetUp,offsetForwards)

These are pretty janky untested additions so it probably needs a bit of ironing out (messing with angles, offsets, backwards characters, cameras, etc etc…), and sorry for intruding

2 Likes

I know I made a mistake but thanks for pointing out! :smiley:

1 Like

this helped create the effect I was looking for, which tied the player to the ball and let me create a custom camera behind them, thanks!

1 Like