How I can keep an rotating object from moving from its place without affecting rotation made through BodyGyro?

Hello Developers,

I am currently working on similar game like Tower Battles and Tower Defence Simulator. I am having trouble with Towers meaning characters that shoot in direction of the enemy. But they move out of their spots during rotation that is made through BodyGyro, CFrame properties. How I could make my Towers keep their position without affecting their BodyGyro movements? Since Welding will break their rotation.

Here is my BodyGyro setting that keeps rotating an tower in enemy direction.

function lookAtTarget(Target)
	if Target then
		--Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(Target["Torso"].Position.X, Torso.Position.Y, Target["Torso"].Position.Z))
		if Torso:FindFirstChild("BodyGyro") then
		else
			local BodyGyro = Instance.new("BodyGyro")
			BodyGyro.Parent = Torso
			BodyGyro.CFrame = Torso.CFrame
			BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
		end
		Torso:WaitForChild("BodyGyro").MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
		Torso:WaitForChild("BodyGyro").P = 10000
		Torso:WaitForChild("BodyGyro").D = 1
		Torso:WaitForChild("BodyGyro").CFrame = CFrame.new(Torso.Position, Vector3.new(Target["Torso"].Position.X, Torso.Position.Y, Target["Torso"].Position.Z))
	end
end

Any ideas how I could prevent tower from moving from it’s spot without affecting their BodyGyro rotation?

If you just want to specify a point in space, you can use a BodyPosition

1 Like

I will try that. I will reply as soon as I test it. Thanks.

They keep their position which is good, but do you have any idea, how I could keep their Torso straight without affecting their Rotation?

You can use an AlignOrientation constraint. Set the type to PrimaryAxisOnly and Parallell, and rotate the attachments both have their PrimaryAxis vertical. You can parent the second attachment to game.Workspace.Terrain, so you avoid having an extra part around.

1 Like

Now I’m fully aware of what BodyGyro is. Thanks for the info!

You could try tweening the object’s lookvector

2 Likes

This is old post, and I figured myself, but I will mark your response as the solution anyways.