How would i make this gun more stable?

the gun works just fine when it is anchored, but when i put it on a car, it freaks out, but still works a bit.


was playing a game on roblox, that was the backround sounds
here is the script:

local event = game:GetService("ReplicatedStorage").Events.GEEE
local e = script.Parent.Handle

event.OnServerEvent:Connect(function(plr,lr)
	local spreada = CFrame.Angles(0,-1.571,0)
	local direction = (lr - e.Position).unit
	local boi = (e.Parent.Position+Vector3.new(0,1.571,0)) + direction
	e.CFrame = CFrame.new(e.Parent.Position+Vector3.new(0,1.571,0),boi)*spreada
	--On the client script gets the player that is in the seat and transfers Mouse.Hit.Position to here
end)

here is an image of the model in the explorer if you want it:
Capture_2020_03_22_08_07_42_589

1 Like

This is most likely because you are directly manipulating the cframe of the object instead of using the constraints to rotate it. Try doing that instead.
You can also rotate it by modifying the attachment CFrames instead which are relative to the part it’s stuck on.

2 Likes

and how would i do that? (i am preaty new to scripting)

If you are trying to rotate a hinge, set it to Servo and change the TargetAngle property.
If you want to use an attachment, Just set the attachments CFrame of whatever attachment (not constraint) the gun is welded by.

1 Like

it seemed to work, but theres a new problem of it not being rotated properly:

If you want to make it point at the mouse you need a mounted turret constraint system. This means you have 2 typical things.

  • A rotating circular platform
  • Some way of rotating the turret up and down from this platform

Then you can try something like getting the angles from the object it is attached to like so:

local roll, yaw, pitch = object:ToObjectSpace(
    CFrame.new(object.Position, mouse.Hit.Position)
):ToEulerAnglesXYZ()

and use these to rotate it

i just realized that the upper limit was set low, and when i set the upper limit to a high negative, and then the gun doesn’t pull the car with it.

but that makes it so the gun falls behind the car. But this is an easy fix, which adds the velocity of the base to the gun position, so now it doesn’t fall behind.