So I have a barrel that I want to rotate around a moving object, I have the code for the moving object, and the rotating barrel still needs some work, but what I’m having trouble with is having the barrel stick to the base.
Heres an image of what I’m talking about:
The red arrow shows that the whole character should move (which it does), and the blue arrow shows that the barrel should rotate around said object.
I have a part to which the barrel is attached to placed in the exact middle of the object. This part rotates to where the player’s mouse is hovering. What I am having trouble with now is making the rotating part, stick to the object. If I use a weld, the rotating part won’t rotate but instead messes with the object’s movement as it tries to turn. if I move the rotating part to the object’s CFrame every heartbeat, the rotating part lags behind the object slightly.
So here’s my question: What could I use/do to attach the rotating part to the Object?
If you want to help with my problem with the rotating part's orientation, expand this.
My Problem with the rotating part is that even when I limit my CFrame.LooKAt()
to only the X and Z and make Y = 0
, the rotating part still will aim a little up or a little down.
Here’s an image and my code:
Blue is what the orientation should be while red is what it currently is.
ServerScript
local MousePosEvent = script.Parent.Parent.MousePosEvent
MousePosEvent.OnServerEvent:Connect(function(player, mousePosX, mousePosY, mousePosZ)
script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, Vector3.new(mousePosX, 0, mousePosZ))
end)
LocalScript
local RunService = game:GetService("RunService")
local Bot = script.Parent.Parent:WaitForChild("Bot")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
RunService.RenderStepped:Connect(function()
local BotObject = Bot.Value
local RE = Bot.Value:WaitForChild("MousePosEvent")
RE:FireServer(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z)
end)
Edit:
Latest progress: How can I connect a rotating part to a non rotating object? - #3 by MRBOGO_YT