How to tween the Orientation of a model?

Hello Developers,

I’m trying to tween the orientation of a model, which is a spotlight, but I have no idea how to do it and all of the tutorials I found were too confusing for me. Here is one of them I tried to understand:

And this is what it looks like if I try to tween the PrimaryPart:
https://i.gyazo.com/70d7a216c21cd9f3eafb188816ebad41.mp4

If you have any idea how to do this and how to explain it well, please do so!

Try welding the parts together so when you tween the primary part, the other parts are going to follow. If that doesn’t work you can use SetPrimaryPartCFrame() and figure out the CFrame.

1 Like

If your model is moving like that then either you haven’t welded the model together properly or one of the parts there is still anchored considering it’s not moving around with the lamp base. I’ve tried to simplify the information as much as I could there: what confuses you about the tutorial?

Adequate programming knowledge is recommended to understand that tutorial, so if you lack that, it could be another cause for not understanding the tutorial, but I’m interested in knowing from your perspective where you don’t understand that tutorial.

Some information about your model setup would be appreciated as well.

2 Likes

I’ve never used welds before, so that’s probably why I don’t understand it. Here is the setup of the model:
image
And here’s the model with welds:
https://i.gyazo.com/16fd0d638f71dbf52bee92bcd62f7560.mp4

There’s code in the tutorial that supplies a way to weld your model together with WeldConstraints so that you don’t have to puzzle over this work yourself if you aren’t familiar with it. It is under the Attaching the Model header. That part it seems you skipped over.

If your spotlight model is directly in the workspace, then you can use the code there but change Panel to Spotlight in the first variable declaration, remove the CanCollide = false bit at the end and run that. It will rig your model up itself by welding the model and then setting Anchored accordingly.

Tweening the PrimaryPart then should also have the other parts follow in suit.

1 Like

It isn’t working for some reason, I’ve followed your steps but it still does the same thing it did before. It does add the WeldConstraints, it just doesn’t do anything. Maybe it’s because of the script? Here it is:

local TweenService = game:GetService("TweenService")

while true do
	wait(1)
	local Main = script.Parent.PrimaryPart
	
	local goal = {}
	goal.Orientation = Vector3.new(math.random(-10,14),math.random(23,70), math.random(16,43))
	
	local tweenInfo = TweenInfo.new(0.5)
	
	local tween = TweenService:Create(Main, tweenInfo, goal)
	
	tween:Play()
	
end

Here’s the model now:
image

Change from tweening Orientation to tweening CFrame. The rotating example on the thread uses a rotated CFrame to tween rotation.

1 Like

The whole model actually moves now, which is good, but now it doesn’t rotate where I want it to rotate to…
https://i.gyazo.com/5cf334c2d106b4458acc62b37235a0f5.mp4

local TweenService = game:GetService("TweenService")

while true do
	wait(1)
	local Main = script.Parent.PrimaryPart
	
	local goal = {}
	goal.CFrame = Main.CFrame * CFrame.fromOrientation(math.random(-10,14),math.random(23,70), math.random(16,43))
	
	local tweenInfo = TweenInfo.new(0.5)
	
	local tween = TweenService:Create(Main, tweenInfo, goal)
	
	tween:Play()
	
end

Sorry for asking so much, but I’m not experienced with CFrame at all. In fact, I just started using it.

1 Like

In this case, it’s just about playing around with the values a bit until you can find a sweet spot that you like. The CFrame bit is a little different from Orientation so extreme values like that might appear. Feel free to plug in any numbers there. :slight_smile:

(I’m not too good with CFrames either, just basics.)

1 Like

Thank you so much for your time, I really appreciate your help!