Hi,
I have a dresser model that’s open and closed. How do I make it with a proximity prompt that if interacted it changes to the open model?
Is this possible? Or is there an animated version possible too?
Hi,
I have a dresser model that’s open and closed. How do I make it with a proximity prompt that if interacted it changes to the open model?
Is this possible? Or is there an animated version possible too?
i dont know how to script- but maybe a script that changes the mesh ID to the other one? sorry i have no idea how you would script that tho
If you want to, you can add a animation into it and make it open, then you can script it to play whenever you open it.
( I don’t know the script, I will not paste here! )
You could use a tween
Also, there are two ways to do proximity prompts in your game. One is to have them in each script the other is to use them in the server script service. Please reference the attached file if you want to use the latter method.
DrawerOpenProxmityPrompt.rbxl (63.3 KB)
If you don’t want to use a Tween and simply want to replace the model you could either hide the model by setting it’s transparency to 1 and setting the transparency of the other model to 0 or you could destroy the model and summon the correct version from ReplicatedStorage.
Use a PrismaticConstraint that connects each singular drawer to an invisible, anchored part that acts as a placeholder. Place attachments in each placeholder and each drawer and link them up with the PrismaticConstraints accordingly.
Make sure the yellow arrows (local X axis) of all attachments are pointing toward the back of the drawer.
Lighter Wood is the drawer (unanchored), the purple block is the holder (transparent and anchored. Add attachments to the two and make sure their yellow arrows are facing the back. Then just connect prismatic constraint w/ properties listed below.
PrismaticConstraint Properties:
Set the UpperLimit to the length of drawer you want to show when open.
Set Restitution to about 0.5.
By changing the LowerLimit of the PrismaticConstraint with a script, you can smoothly open and close drawers using physics. Make sure LowerLimit is always less than UpperLimit.
As for the code,
local proximity = ...
local drawer = ...
local prismatic = drawer:FindFirstChildWhichIsA("PrismaticConstraint") -- or find it using name
--// Create State Attribute
drawer:SetAttribute("State", false)
--// Listen for State Attribute Change
drawer:GetAttributeChangedSignal("State"):Connect(function()
if drawer:GetAttribute("State") then -- if state == true then open
prismatic.LowerLimit = prismatic.UpperLimit
else -- if state == false then close
prismatic.LowerLimit = 0
end
end)
proximity.Triggered:Connect(function()
drawer:SetAttribute("State", not drawer:GetAttribute("State")) -- Sets the state of the drawer to be the opposite of the current state (if opened then close; if closed then open).
end)
I wrote the above code in this textbox, so it might throw a simple error that you can easily fix.
Hope this helps!!