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"

2D Procedural Level

Hey guys,

I'm working on a 2D game where I want the level to be generated as you go. I have a bunch of level elements that I just want to be spawned one after the other, it should be dead simple. I've run into a bit of a problem with something that I thought would work..

I'm using 2 variables, SpawnLocation, and PreviousElementWidth. SpawnLocation's starting value is 512, I have a bit of ground before I want the random stuff to start. PreviousElementWidth's starting value is 256.

Here was my logic: I calculate where to spawn the next element by taking the PreviousElementWidth dividing by 2 so I know where it ends, adding this to the element I'm about to spawn's width divided by 2, and finally adding this to the SpawnLocation. Sadly it does not work, sometimes the elements will overlap, and sometimes there will be gaps between them. The odd thing is if I set my random Integer in Range to 0 - 0, 1 - 1 and so on it works fine, no gaps or overlapping.

My LevelElementsArray is a struct that contains references to my level elements actors and the width of them

  • 0 - 256

  • 1 - 128

  • 2 - 16

  • 3 - 68

Pretend my Random Integer in Range is from 0 to 3 myblueprint

Product Version: UE 4.7
more ▼

asked Jul 06 '15 at 11:07 PM in Blueprint Scripting

avatar image

83 18 21 32

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

1 answer: sort voted first

I went over the math this morning and found out that it was all correct, and then realized it might be because a new random number is generated each time that is called. I ended up fixing it by generating it once, saving it in a variable and then always just pulling from that variable.

alt text

more ▼

answered Jul 07 '15 at 03:55 PM

avatar image

83 18 21 32

avatar image Candy_swift Jul 08 '15 at 08:02 AM

Thaks a lot! Your question and your answer helps me to understand the logic of making procedural levels!

(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