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"

Best way to calculate the age of something??

Im creating a nature simulation game with heavy RTS elements. I have a lot of animals and plants that the player can place in their environment and they all have a lot of things that I need to calculate (Age, Fruit production, gestation lengths etc.)

My current method is using an event bound to a looping timer. So every second (Time Unit) the event fires and adds +1 to lets say the age.

Ive then taken that Time unit and multiplied it by a float called "Game Speed" Which seemed to be working fine or so I thought. When I used a dispatcher to set the game speed variable in order to increase speed and make things move along faster. It appears to be skipping the +1 to the age in random cases... I can not for the life of me figure out what to do about it.

My best example is I have a patch of grass in game. It has a component which uses the above method only it decreases a float variable "Lifetime" by 1. Then when Lifetime reaches <=0 the grass patch dies. But it doesn't... It carries on long past when it should.

Is there any better way of doing this? Other than to use the event tick.

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '19 at 08:54 PM in Blueprint Scripting

avatar image

rconnor410
6 1 1

avatar image Nebula Games Inc Mar 11 '19 at 11:24 PM

As the below answers state you should have an actor keep track of the "time". Here is a link to a tutorial that will give show you how to create a custom blueprint node that will generate a "time stamp" and also output a "date" for you to keep track of things. You can then simply compare times/dates of when things were created. Hope this helps.

https://youtu.be/7A7criIbmgc

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

2 answers: sort voted first

Have you tried using the increment node instead perhaps? Is your time in integers? If so, increment works wonders.

more ▼

answered Mar 11 '19 at 09:05 PM

avatar image

Crowley Caine
693 8 10 16

avatar image rconnor410 Mar 11 '19 at 09:38 PM

Used that. Its given me a much smoother increase but its still doing the same thing :(

avatar image Crowley Caine Mar 11 '19 at 09:40 PM

Setting a break point would help you narrow down and figure out why that part of the script is not being triggered. Maybe it could have something to do with calculation load but I kinda doubt it.

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

Probably a solid way to do it would be to have a time manager (ie, your game mode) and each actor to just log their time of creation. This way there's only 1 object keeping track of time, and all other just read from it.

Then you can check as frequently as needed to to see how old it is:

 GameMode current time - Actor creation time = Actor age

Then all the actors have to do is to evaluate their ages to see what it is they should be doing.

more ▼

answered Mar 11 '19 at 10:28 PM

avatar image

Evigmae
1.7k 8 4 8

avatar image Crowley Caine Mar 11 '19 at 11:13 PM

This is a very good way to go about it. You'd have a master "clock" keeping track of ingame time and the objects and actors only need to look at it. If you wanted to simplify it further you could have "growth times" at set intervals, where a message would go out to the actors in the level and they would decide if ot was time to grow. Less constant strain and if it's efficient enough there shouldn't be any hiccups. Lots of games do this. Plus you can set the growth time in smaller increments so it doesn't seem so artificial.

(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