x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 alt text

Product Version: UE 4.18
Tags:
puzzle-box.png (254.5 kB)
more ▼

asked Nov 08 '18 at 05:13 PM in Blueprint Scripting

avatar image

SPhillips6
5 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text

alt text

capture.png (268.3 kB)
capture1.png (476.6 kB)
more ▼

answered Nov 08 '18 at 11:51 PM

avatar image

ThompsonN13
7.6k 21 6 16

avatar image ThompsonN13 Nov 09 '18 at 12:18 AM

below is an example of how you could check the results automatically. first create a custom event (check positions), then you want a branch and the result in your case the open lid event. now the conditions of the branch will determine if the gems are in the right locations so we just need to compare their locations to the correct ones via the equal (==) node. now we need a bit of logic to say i only want the branch to be true if all the gems are in the right locations so we use a and node. a and node checks to see if all the inputs are true before it will output true, so if even one input if false the output will be false.

also node that i am calling the check positions every time the gems move so once all are in place then the lid opens on its own. i also collapsed the nodes from the above examples for my own sake during testing.

alt text

capture.png (417.2 kB)
avatar image SPhillips6 Nov 09 '18 at 07:58 PM

I'm reading all this and my mind is blown! I'm gonna give this a go now if I get a chance, if not I'll try tomorrow, but thank you for the answer! :D

avatar image SPhillips6 Nov 10 '18 at 02:52 PM

how do I set on click events because mine are not working and I can't seem to find it at all, I'm using a first person character, and cant seem to find them D:

avatar image ThompsonN13 Nov 10 '18 at 03:36 PM

if your trying to find the node for the click event then try selecting the component you want the click event for then go to the details panel and scroll to the bottom, there will be a events section near the bottom with a bunch of green buttons, click the on click one.

if you have the event nodes but they arent working then theres a few things you need to make sure of. first make sure you have the set show mouse cursor and enable click events boxes checked in your player controller. second make sure that the object to be clicked blocks the appropriate channel for your clicks (visibility channel by default).

alt text

capture.png (23.1 kB)
avatar image SPhillips6 Nov 10 '18 at 03:40 PM

I was using the first method to move the gem, but when Im moving the gem, it does its 4 locations set in gem locations, but when i go to return the value ( so its original starting position) it zooms off somewhere and then i click it again it then starts working again, any idea why this happens?

avatar image SPhillips6 Nov 10 '18 at 03:44 PM

I think for some reason its going to the centre point of the box that its connected to

avatar image ThompsonN13 Nov 10 '18 at 04:03 PM

it sounds like you have a bad location in your array or your getting a index which is out of range. post a picture of your current script and your arrays values so i can see what youve done and make sure its not a simple issue.

avatar image SPhillips6 Nov 10 '18 at 04:06 PM

alt text

bp.png (401.5 kB)
avatar image ThompsonN13 Nov 10 '18 at 04:45 PM

hmmm looks right there. you may need another check for the get connected to the lerp b pin to make sure it gets a valid index. basically all you need to do is after the add (+) node, have a greater than (>), drag off the array and search for last index and connect that to the second pin on the greater than node. then plug the greater than into a select node. have the select node True pin be 0 and the False pin be the value coming out of the subtract node. last connect the select output to the get. thats the only place i can think of where there may have been an issue

alt text

capture.png (103.5 kB)
avatar image SPhillips6 Nov 10 '18 at 05:55 PM

Thank you! works perfectly :)

avatar image ThompsonN13 Nov 10 '18 at 06:44 PM

no prob. you can actually use that some type of thing in the top right section the script too (off the timeline finished pin). using this section of script there would allow you to use as many locations as you like and it will become more reusable being able to adapt to different sizes arrays. what this means is you could have a gem puzzle where the gems move in a circle of 5 positions if you wanted to.

avatar image SPhillips6 Nov 11 '18 at 08:31 AM

Im guessing that the GET node when checking to see if its in the correct position correlates to what ever number is in the 'correct positions section', so for example if 'gem 1' had position of 2 in 'gemlocations' I would put 2 in the 'correct positions' integer and the 'GET' would had the number 0 because the first line of 'correct positions' is 0?? if you get what i mean

avatar image ThompsonN13 Nov 11 '18 at 02:54 PM

im guessing your talking about the picture about 12 posts ago. yea what your saying sounds about right. the only thing i did a little different is in the example i showed i used indexes which correlate to gem number but thats just a style choice to make things easier to understand.

avatar image SPhillips6 6 days ago

Just wondering, I'm moving on to my screwdriver Puzzle and im using the same movement by using the vector array so that it moves on click. But when it gets to the end where its meant to finish, if I click again it rewinds the handle and then if I click again it just keeps rotating. Just wondering how can I make it so that when its reached 4 in my array that it stops moving. alt text

avatar image SPhillips6 6 days ago

doesnt matter Ive set a booleen at the start of it all and at the end, so that when it will allow me to move my prong :P

avatar image ThompsonN13 6 days ago

all you would need to do is to delete everything after the ++ node and add a branch before the timeline with its bool set by a: is current position greater than 4. that will stop the script from looping and stop any click events beyond the fourth.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question