Turrent not moving to mouse

Hello there.

Recently, I have creating a topic concerning a similar matter however I haven’t found a answer which solves my problem. This time however, the issue is that I’m trying to get a turrent to move to the right or left 360 degrees wherever the mouse is facing but instead what it does it it moves the whole entire boat with it.

Here is my code:

while true do
	for i,v in pairs(Turrent.Parent:GetDescendants()) do
		if v:IsA("Part") then
			v.CFrame = CFrame.new(v.Position, Mouse.Hit.Position)
		end
	end
	
	task.wait()
end

I’m not sure on how to fix this as I have been stuck on it for a few days now. Any help is appreciated, thanks!

You need a weld and to use Weld.C0. It needs to be in object space with the CFrame oriented to the root of the turret.

1 Like

I am using the qPerfectionWeld in the whole entire Boat so it doesn’t fall apart. Is this the issue? if so, how would I use Weld.C0 t0 change the CFrame?

Could you please elaborate?

I’ve tried using Lookvector however it makes it a lot worse. Anyone have any solutions?

Could you show some images or a video of what you mean by “moves the whole boat”? And also how the turret is attached to the boat

1 Like

Here is what I mean by it moves the whole boat:

External Media

And here is how the turrent is attatched to the boat:

image

I just have a qPerfectionWeld to Weld the whole boat together. The turrent is the “BigGun”

1 Like

What’s the boats primary part, and for the weld connecting the turret to the rest of the boat, what are the part0 and part1 properties?

Are you talking about the “Cruiser” model? If so it does not have a PrimaryPart.

The turrent I’m talking about is the BigGun and I’m pretty sure its connected to the seat.

I think it may have an issue regarding the Welding script however I’m not sure. I was told to use the Weld.C0 however I’m also not sure on how to manipulate it into how I want it to be. I can show you the properties of the Turrent if you would like.

1 Like

yeah, so what I think the issue is that because you’re editing the cframe directly, it also moves all the parts that are welded to it. The c0 and c1 properties of a weld just determine how the parts are offset from each other. So if you edit those values directly, you can achieve the correct rotation without moving the entire assembly. Don’t 100% remember off the top of my head if you have to edit the c0 or the c1, but you can play around with those values and figure out which one needs to be offset.

Could also try adding a motor6d instead of a weld for the turret, because it has the c0 and c1 properties displayed and you can use that to figure out how the parts are supposed to work with welds because it’s the same thing

1 Like

Don’t both motor6d’s and weld’s have the C0 and C1 properties? I’m not too experienced with motor6d’s and my history working with them isn’t great either.

I can try edit the C0 and C1 values directly, do you reckon I’d just set it to the CFrame of the mouse?

1 Like

Yeah, so for the motor6d comment I just said that because it has the c0 and c1 properties that can help you visualize the offset on the properties window. (welds don’t have this)
image

Also found this similar thread from a while back where I did something similar but instead of connecting it with a weld, i connected it with an alignposition and rigidity enabled, then changed the cframe of an alignorientation to match what I wanted.

Thanks a lot, I will try it out when I get back.

It shouldn’t be a Motor6D, since those are not as performant and are slower for performance. A Weld is always better unless you’re planning to use DeiredAngle or Transform (animation editor).

False. They do have this.

What I mean by object space is CFrame.ToObjectSpace, which is very easy to use. You’d do yourCFrame:ToObjectSpace(yourTurretRootPart.CFrame.

read what i said again

I did, both have C0 and C1. I don’t think you checked.

Do you possibly have any example of code that I could work off of?

v.C1 = CFrame.new(v.Position, Mouse.Hit.Position)
v.C0 = CFrame.new(v.Position, Mouse.Hit.Position)

And how could I implement get the CFrame to use ToObjectSpace on? thanks.

You’d do ToObjectSpace(yourRootPart.CFrame).

So I’d put it in a while loop and whenever the mouse turns I’d run:

ToObjectSpace(PrimaryPart.CFrame)

How would I also move the C1 and C0 efficiently?

No, you’d do

in a loop. The loop could have task.wait(.1) or heartbeat if you want.

1 Like