Rotating issues

Heyo! I have been having some issues rotating a model of mine. The main body/HumanoidRootPart rotation is successful, however when it comes to the upper body’s rotation, that is where issues arise. I have been trying to fix it, however I can’t really begin to understand how.

To explain it simply, I have a tank model that has 2 parts, the HumanoidRootPart or lower body and the upper body. The lower body moves depending on where the player wishes to go and it faces the direction of movement. For instance, when the player taps “D”, the lower body faces to the right and so on. The Upper Body rotation is based on the mouse, it always faces the mouse position on the screen. That works, however it is where the issue lies.

Alright, so whenever I turn around the lower body of the tank, the upper body rotates with it, however it doesn’t align with the mouse position whenever turned. It only aligns with the mouse whenever the lower body is facing upwards. I have included below a video reference showcasing the issue at hand.

[-] https://gyazo.com/792ae3db7d27a61cb9e79c7618542a9f

I have tried searching everything on the DevForum, even asking for external help, however I wasn’t able to combat my issue. It is important to keep note that the Lower Body is connected with a Motor6D with the UpperBody and the LowerBody is connected with a Motor6D with a third part called Rotation, though that isn’t of importance.
Below is my code for the lower body rotation:

Basically all I am asking is, how do I rotate them individually without the systems breaking. Keep note that whenever the lower body turns, everything turns with it. I believe that could be the issue and I have to manipulate the C0 property of the Motor6D to achieve rotation only for the HumanoidRootPart. I appreciate your help.
Part0 → HumanoidRootPart/LowerBody
Part1 → UpperBody.
The Motor6D is called UpperBody and is a child of the PrimaryPart which is the HumanoidRootPart.
The second Motor6D is called RotationMotor:
Part0 → HumanoidRootPart/LowerBody.
Part1 → Rotation ( The third part that moves alongside the UpperBody with the help of a weld constraint)

I managed to fix part of the issue, however I need a bit of more help.

I made it so the rotation of the Upper Body does not interact with the rotation of the lower body, but a few issues popped up:

[-] https://gyazo.com/9200dad990d433374f4dfba8c349128b

The tank doesn’t face correctly depending on the player’s movement and the move direction. New script:

if moveDirection.Magnitude > 0 then
		local newLookVector = moveDirection
		local currentLookVector = PrimaryPart.LowerBody.Part1.CFrame.LookVector
		local angleBetween = math.acos(currentLookVector:Dot(newLookVector))
		local targetC0 = CFrame.Angles(0, angleBetween, 0)
		PrimaryPart.LowerBody.C1 = PrimaryPart.LowerBody.C1:Lerp(targetC0, smoothingFactor)
	end

How do I calculate the angle I need it to turn to depending on the move direction?

I was able to calculate the angle needed to turn, but there is one small issue.

[-] https://gyazo.com/7e5a72c4d62c7dedfe05624e43ca9e8a

As you can see from the above video, when I turn right, the front face of the part as indicated by the Orange outline faces to the right, when I go left it faces to the left. However when I go up, it faces downwards and when I go down it faces upwards. How do I make it so, when I go up, it faces upwards and when I go down it faces downwards?

Revised Script:

        local newLookVector = moveDirection.Unit
		local correctedLookVector = Vector3.new(-newLookVector.X, -newLookVector.Y, -newLookVector.Z)

		local targetCFrame = CFrame.lookAt(Vector3.new(), correctedLookVector)

		local _, _, _, xx, yx, zx, xy, yy, zy, xz, yz, zz = targetCFrame:GetComponents()
		local targetRotation = CFrame.new(0, 0, 0, xx, yx, zx, xy, yy, zy, xz, yz, zz)

		PrimaryPart.LowerBody.C1 = PrimaryPart.LowerBody.C1:Lerp(targetRotation, smoothingFactor)

If anyone could assist me, I’d be grateful! Thank you in advance.

I finally fixed it!

[-] https://gyazo.com/e18923d11030aa36f0b2fab51db3f0a2

As you can see the front face of the tank always faces the direction of movement. I had to tweak the script here and there and I made it.

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