How do you move a static mesh component to different places?
Hi, Im working on a puzzle game and the gems on the puzzle box move by clicking on them, but i need a sequence for when clicked. -click once move left -click again moves back to centre -click again move right -click again moves back to centre Repeat I've tried numerous things but it's not working for me. I need them so that they have to be in a certain place for the puzzle to open. So when all Gems are in the correct place the lid will come off. alt text
asked Nov 08 '18 at 05:13 PM in Blueprint Scripting
below are two examples of how this could be done in a similar manner to what your doing now, do note that you will need to tweak this depending on your specific needs. the basic idea here is that you need to be looping through 4 locations where you want the gem to be located (center, left, center, right). we first need to have a way to determine where the gem is, to do this you just need a integer variable (in my examples its GemXCurrentPosition). now we want to increment the integer each time the gem is clicked and eventually have it loop, this is done in the top right section of the pictures below where we get the integer then increment it and check to see if its larger than 3, if it is larger than 3 we set the value to zero essentially looping it (this is zero based so 0 1 2 3 represent each position). so thats how we track the location now the rest of the script is about moving the gem. the basic moving method used is a timeline that lerps between two vectors and sets relative location.
in the first picture the method used to set the vectors is to have a predetermined array of locations. as you can see in the bottom right i used a offset of 50uu to represent the left and right locations. for the lerp we get the location stored in the array using the current position as the index. we also get the next position in the array by getting the current position plus one or the next index. this method allows you to make things more modular and reusable. for example you could use the same array for many gems but add a offset in the z direction if you wanted the gems to be in a column.
the second picture shows another method where have the locations the gem moves to based on components in the bp. for this method i used scene components to mark the center left and right positions. basically here you get the scene component based on the current position, then get the scene components relative location. note the offset of the list in the second select. this method is probably a bit easier to understand but requires a little more work and is far less modular.
those are the basics on moving and setting the position. now you just need to create a event to check if the positions are correct. with the variables you have that store the position it should be easy to just compare the current location to the correct ones. ill try to make a example of that in a min.
answered Nov 08 '18 at 11:51 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here