Funcationality of Part:PivotTo()

I am currently attempting to create functional night vision goggles, which rotate down from a neutral position to the eye level of the player’s character.

Example

image
image

I had originally found a way to do this using PivotTo, however this only works if the moving part is anchored/Motor6d is disabled, so I created this solution which temporarily anchores it and sets the CFrame

Code
function rotatePart(part, degrees, axis : Vector3)
	local a = axis.Unit * Vector3.new(math.rad(degrees),math.rad(degrees),math.rad(degrees))
	local FinalCFrame = part:GetPivot() * CFrame.Angles(a.x, a.Y, a.Z)
	local Motor: Motor6D = part:FindFirstChild('Moving')
	
	part.Anchored = true
	part:PivotTo(FinalCFrame)
	
	Motor.C0 = Motor.Part0.CFrame:ToObjectSpace(part.CFrame)
	part.Anchored = false
end

while true do
	wait(.01)
	rotatePart(script.Parent,5,Vector3.new(0,0,-1))
end

And then this leads me to know, where I’m trying to get the CFrame that pivot to would use, without actually moving the part. If anyone has any ideas they’d be a great help

Thanks in advance

3 Likes

I havent read anything but use this:

--Note: PivotTo only works on MODELS, NOT PARTS
local Pos = --target position
local Rot = --Target Rotation
TargetModel:PivotTo(CFrame.New(Pos, Rot))

Fill in the blanks for the things, And no you cant “Not” use Pos or Rot, that would return an error.

Edit: Maybe use tweenservice? Its much better at things like this. I wouldnt bother animating the goggles? there is no need for a motor6D in something that only goes up and down at stays attached to the player.
Even then its far to simple to even use Tweenservice to begin with.
Try this:

  • Make a rotation part anchored to the player’s head.
  • Weld the goggles to the rotation Part using either welds or weldconstraints.
  • Make a script that interpolates rotation between the equipped en unequipped status
  • Make the keybinds work and boom your done.
1 Like

PivotTo does, in fact, work on parts. They both inherit from PVInstance.
Yes, the motor6d is theoretically not needed (you can just use a regular weld), however they have exactly the same functionality in this case.

Using a part instead of the pivot point is just moving the problem, as long as the pivot “part” is welded to the head it wouldn’t be able to move. So I ask again, how does PivotTo work exactly and how could the CFrame that it uses to move the instance be computed?

1 Like

just use a looped animation of the goggles in the active and inactive position. when you want to activate them you can do anim:Play(1) whatever number you put in the function is how long it will take to move. if you do 1 it will take 1 second to smoothly move down or up.

2 Likes

Brother I am out of ideas, Goodluck trouble shooting with it, I dont run into these problems since I only use the things im familiar with so thats why I thought it wouldnt work on parts.

1 Like

This seems really overcomplicated. Why is there a Motor6D in the first place?

1 Like

Why do you have to use :PivotTo here? Could you not just adjust the motor connecting the goggles to the helmet?

1 Like

I’m trying to not use PivotTo, changing the code to

function rotatePart(part, degrees, axis : Vector3)
	local a = axis.Unit * Vector3.new(math.rad(degrees),math.rad(degrees),math.rad(degrees))
	local FinalCFrame = part:GetPivot() * CFrame.Angles(a.x, a.Y, a.Z)
	local Motor: Motor6D = part:FindFirstChild('Moving')
	Motor.C0 = Motor.Part0.CFrame:ToObjectSpace(FinalCFrame)
end

causes the goggles to spiral away from the character

Video Example

By comparing the CFrame I’ve found that the CFrame PivotTo sets the part’s CFrame to is slightly different (about a difference of .15 studs) than the FinalCFrame variable.

1 Like

Yeah that makes sense based on how your code is setup.

A motor matches the following equality:

motor.Part0 * motor.C0 * motor.Transform == motor.Part1 * motor.C1

motor.Transform is controlled by animations so you can assume that’s just CFrame.identity for all intents and purposes.

You need to pick C0 and C1 such that they match the equality and point that the equality meets is at the hinge of the goggles. Once you’ve got that you just modify as:

C0 = originalC0 * CFrame.fromEulerAnglesXYZ(theta, 0, 0)
1 Like

How exactly can you find the C1 value where this equality holds?

So I think I’ve found a workaround, instead of setting the anchored property it looks like I can just set Motor.Enabled to pivot the part.

Edit: Decided to go with animations instead because of slightly inaccuracies

2 Likes

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