First of all:
Can you post your Actor hierarchy?
For now i think the Drawers are supposed to be child components of the main Shelf Mesh.
Means, you can move your Drawers relative to it.
So… You need a bool array variable, to save if a drawer is open. Means, the array needs to be the size of the Drawer count. Call it “openedDrawers”
F.e. 6 drawers, resize array to 6.
Now a second variable arraybof the same size, to hold the drawer components. Populate it on BeginPlay, by setting the array, draw a link backwars from the input and use the makeArray node.
And create an int to hold an index.
And as last, an Array for vectors, same size as the other two. In here, when populating it in BeginPlay, you get each drawer component, get its relative location and add the distance to travel. Where to put the distance?
To make it easier for you, open the Actor viewport and select a drawer.
You’ll see the Transform Goku (red/green/blue cross).
Remember which color heads into the correct direction. Each color represents a field in a vector.
Red is x
Green is y
Blue is z.
Remember the field.
Back to the graph, where we want to add a value to the vector arrayfield.
Leave the values you don’t need at 0, and only fill the needed value with the target distance.
Means, if you wish your drawer to move 50 in that direction, put 50 in there.
Your trace looks correct, so lets talk about the open/cloning.
You from the trace result, get the component and check it against your drawer array.
Therefor, you need a foreach loop with break. On every loop body check, if the component of the trace == the current loop object.
If true, set the index int to the current loop index, and break the loop (draw a line from the set int to the break input of the foreach loop, use reroute nodes to make it look more clean).
Now you know the index of your used drawer inside the drawer array.
Now, draw a new line from the Complete Output of the loop. Add a DoOnce here.
From the doOnce, link a branch.
Since your Drawer Array has the same size as the bool array, you can use the index variable to get the right value from the bools.
Check, if the value of openedDrawers is true or false, with a branch.
From false(!), create a timeline and link the branch to play from start
Now a trick:
Link the true(!!) Intro the timlines
Play reverse from end.
With this, you only need ONE timeline for both actions.
Open the timeline (doublecklick it) and in the curve editor, add a new float curve… Call it alpha and give it a length of your desire…
Add a keyframe on 0, with a value of 0.
Add a keyframe at the end with a value of 1.
Back to blueprint.
From the Update Output, add a
Set Relative location.
As target, take your Drawer Array and the index, to get the correct drawer.
Now, as in your original, put in a lerp as target location, to lerp two vectors.
As vectorA, take the drawer from the array again, get its relative location.
As VectorB, take your vector array, get an item with your index int and link it as VectorB.
As alpha value of the lerp, link in the timelines alpha.
Now, from the Finished Output of the timeline, link a setArrayElement. As Inout array, take your bool array and index is your int. The item value to set is:
Take your bool array and get the right value with your index int. Link a “NOT” operator here, and from the NOT draw a link into the setArrayElement.
After this, you just draw a link back into the reset of the doOnce, so you can fire your code again.
Thats it, i think.
Eine that a fee times for FPS Examples and learning.
Ps.: Sry for not providing images… My pc is kinda broken and i first need to fix some issues with the CPU