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
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
--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
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?
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.
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.
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.
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: