How could I stop this behaviour from occuring?

Hello there,

I’m creating a moving turrent and It moves however i’m trying to make it so its moves around a part.

External Media

As you can see the turrent moves however it goes a bit further than the metal square sometimes. I’m trying to get it so its moves around the metal square.

I’ve tried experimenting with the PivotTo

Any help is appreciated, thanks.

2 Likes

I think setting the PivotTo property to 5,0,0 lowers the distance between the turrent and metal square however I still haven’t found a suitable solution.

Well seeing some code would help us better help you but it looks like your just making the turrent look at the mouse position, I’m not sure your making it relative to the metal sqaure

1 Like

What’s happening is you’re just rotating the turret around it’s centre.
What you could try is taking the mouse’s 2D position on the screen and then use that to control the speeds of a horizontal and vertical Torque on the turret, however you’re going to have to work out where the hinges go yourself.

Here is my code:

local TurrentBody = Turrent.TurrentBody

UserInputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		Mouse.TargetFilter = Turrent
		
		
		TurrentBody.WeldConstraint.Enabled = false
		TurrentBody.CFrame = CFrame.new(TurrentBody.Position, Mouse.Hit.Position)
		TurrentBody.WeldConstraint.Enabled = true
	end
end)

How would I take the mouse’s 2D position?

Here is my code:

local TurrentBody = Turrent.TurrentBody

UserInputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		Mouse.TargetFilter = Turrent
		
		
		TurrentBody.WeldConstraint.Enabled = false
		TurrentBody.CFrame = CFrame.new(TurrentBody.Position, Mouse.Hit.Position)
		TurrentBody.WeldConstraint.Enabled = true
	end
end)

I’m not using hinges to control the turrent movement only changing the TurrentBody which is a union’s CFrame.

If you look at the video you can see the entire turret moving around it’s pivot point. You need to set a model’s PrimaryPart so the script rotates around the location you want (or set the Pivot of the Model using the Pivot Editing tools in the Model Tab in Studio.

For this type of turret you want 2 points of rotation.
The base should be it’s own model and it should have the Cylinder as the PrimaryPart so it rotates around it.
The cannon should be a model and have its PrimaryPart as the pivot point for the gun.
Make the horizontal movement of the mouse move the base and the vertical movement tilt the gun and player seat.
It’s a bit more work, but it’ll make it work better.

If you want to make it all one piece then I’d suggest putting a Ball Part under the Cylinder and make that the PrimaryPart of the entire gun. That way your CFrame script will rotate and tilt around the Sphere and it won’t look as twisted as your setup.

1 Like

Thanks for the response, I’ll try it when I get back.

I made an anti-aircraft gun in my Bomber place if you’d like to take a look.
It’s driven by the VehicleSeat controls so the control system won’t work for you, but you’ll see the movement I mentioned. I used HingeConstraint set to Servo for raising and lowering since that is limited, and one set to Motor for the rotation since it can keep going in circles.

Just have a look at my Roblox profile places, it’s the B-25 bomber. The anti-aircraft gun is close to the spawn.

Sure, I’d love to take a look.

Since the whole gun is a union, I made a model with only the diamondplate base in it and put the union in the model, after I set the PrimaryPart of the model to the union but it still produces the same result.

I thought that if I were to set the primarypart of the base to the union then the union would rotate around the metal square(base)

Since the gun that is moving is 1 union, in that case should I make it a model and then set the models pivot point?

You can edit the Pivot of the Union if there are no other Parts or Unions involved.

1 Like

Everything that is moving is 1 union and I changed the pivot of it to 0,0,6.5 manually but unfortunately it still produces the same behaviour.

Here is what my explorer looks like:

image

And Here is how the pivot looks like in the editing tool:

Is the BigGun the model that is rotating, or just the TurretBody?
If the entire Model moves then set the TurretBody as the PrimaryPart of the BigGun.

1 Like

The Bottom part is that diamondplate your seeing under the circle connected to the turrent and that doesn’t move.

Yeah I’m only rotating the TurrentBody(The union)

I’m not sure the PivotTo property is changing the behaviour of the turrent and I’m not sure of any other method to try and make this work.

While I was messing around with the turrent I found out that when I was creating the union, the first part I selected was where the turrent would pivot off of. So I selected it to a part in the middle of the turrent and it now works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.