Chest only opening correctly on 0 -60 0 orientation

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make the chest open even if i change the scale of its model, rotate it or change position

  2. What is the issue? it works when i move it but when i change the orientation of the chest it breaks.

  3. What solutions have you tried so far? Tried looking in help channels and using chatgpt i also found a fix i think by using a hinge but it’s not the best way to animate it. Chat Gpt is dumb by the way

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- // Services
local TS = game:GetService("TweenService")

--// Essentials

local Chest = script.Parent

local Head = Chest:WaitForChild("Head")
local Bottom = Chest:WaitForChild("Bottom")

local ancientCframe = Head.CFrame

local scale = Chest:GetScale()

local offsetX = -9.8
local offsetY = 10
local offsetZ = -16.975

local scaledOffsetX = offsetX * scale
local scaledOffsetY = offsetY * scale
local scaledOffsetZ = offsetZ * scale

local goalCFrame = CFrame.new(
	ancientCframe.X + scaledOffsetX,
	ancientCframe.Y + scaledOffsetY,
	ancientCframe.Z + scaledOffsetZ
) * CFrame.Angles((Head.Orientation.X), math.rad(Head.Orientation.Y), math.rad(90))

local Open_Anim = TS:Create(Head, TweenInfo.new(1), {CFrame = goalCFrame})
Open_Anim:Play()


1 Like

CFrame.Angles dont use typical degrees
It use Pitch,Yaw and Roll (learn eulers math to understand this terms) its a fromEulerAnglesXYZ constructor behind the scenes actually.
If you want short answer just use CFrame.fromEulerAnglesYXZ instead

Instead of doing math.rad(90) that has some overhead i recomend you to cache constant somewhere “math.pi*0.5”

3 Likes

wdym by cache constant somewhere “math.pi*0.5”

put variable referancing this value where you declear services etc
So it can be accesed in code below.
In other programming languages like c for example there is a keyword “const”

const int newconstant = 42;

Its refering to immutable variable
While in Luau there is no official “constants” this term is still commonly used and is often a good programming habbit.

Compiled to machine code Luau does create constants probably tho if variable doesnt get mutated i think
I could be wrong tho.

i actually need help i really don’t understand.

i wasn’t talking about constants tho i asked how to fix my issue because i don’t really understand why when you change orientation the axis change when you play the game

It doesnt change
You can preview the cframe value
That how CFrame.Angles work
Just use CFrame.fromEulerAnglesYXZ instead

-- // Services
local TS = game:GetService("TweenService")

--// Essentials

local Chest = script.Parent

local Head = Chest:WaitForChild("Head")
local Bottom = Chest:WaitForChild("Bottom")

local ancientCframe = Head.CFrame

local scale = Chest:GetScale()

local offsetX = -9.8
local offsetY = 10
local offsetZ = -16.975

local scaledOffsetX = offsetX * scale
local scaledOffsetY = offsetY * scale
local scaledOffsetZ = offsetZ * scale

local goalCFrame = CFrame.new(
	ancientCframe.X + scaledOffsetX,
	ancientCframe.Y + scaledOffsetY,
	ancientCframe.Z + scaledOffsetZ
) * CFrame.fromEulerAnglesXYZ((Head.Orientation.X), math.rad(Head.Orientation.Y), math.pi * .5)

local Open_Anim = TS:Create(Head, TweenInfo.new(1), {CFrame = goalCFrame})
Open_Anim:Play()

changed it still dosen’t work

fromEulerAnglesXYZ == Angles
You need fromEulerAnglesYXZ

If you’re referring to the math.pi x 0.5 part, I think they refer to the radian representation of a 90 degree angle.

You can see in the diagram here that Pi/2, or pi x 0.5 forms a 90 degree angle. I believe this is used since CFrame.angles only takes radians.

2 Likes

Changed it still does the same thing lol

I just realized
Why don’t you just Weld/Motor6D?
It keeps offset intact already.

If you don’t wanna do this using math, there is a more, albeit probably lazier way you can achieve this effect:

Make a clone of the top part and position and rotate it at where you want the opened top part position to be, then take either a part and copy the top part’s position and orientation to it, make it a child of the chest model.

Then you could just tween the head to that respective target part’s cframe, you just have to save the chest lid’s original CFrame to a variable if you ever want to tween it back.

EDIT: I think only parts would work, don’t use attachments since I think scaling doesn’t change their relative positions

I already know that method but i’m using a part like a hinge and rotating it instead i just wanted to find out why this method wasn’t working.

i think this wa the main cause of it.

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