- Home /
How to move a travelling npc accross scenes in real time
I'm working on a 3D top down rts/rpg project. To save memory, I'm going to divide the world into numerous scenes (like fallout 2, baldur's gate etc).
The problem I face with this is that I want active trade between different towns (located in different scenes) in the world. Moreover, I do not want this trade to be simulated but actual. For example, a cart travels from town A(scene 1), across country road X (scene 2), country road Y (scene 3) and then gets to town B (scene 4). The cart will leave town A with goods, gold or both and make transactions in town B leading to a change in the cart's inventory. When it returns to town A, the town's inventory will also change.
I do not know where to begin with solving this problem. A related problem is creating AI daily routines for a town's inhabitants and to have those routines continue even if the scene is not loaded. As far as I understand it, if a scene is not loaded then all scripts and gameobjects are also paused. Woodsmen and miners stop accumulating resources and fighters stop accumulating skill in the training grounds etc.
Sorry for the vagueness of this question. I hope it's clear what I'm trying to achieve. Any pointers in the right direction would be appreciated.
Answer by getyour411 · Jan 12, 2015 at 01:52 AM
Regarding the scene not running, the way I've solved that is to have a static variable that's essentially a timer (independent of any one scene). When a scene is loaded, my functions look at the time delta and apply/increase/decrease things based on the time. I think you could use that approach to resolve a few of your issues.
For the problem of the cart, consider how are you going to make it move along this country road even with the scene loaded? Will you use an array of hidden gameobjects serving as waypoints that it moves to? If that's the case, you could use the time.delta again to estimate where along the path it might be.
Thanks a lot for your post. I'll start experimenting with your suggestions. It's good to hear that what I want to achieve is not totally impossible... but I can see myself running into a plethora of issues. The first one I can imagine having trouble with is animations, equipment and transforms.
Using the time variable I could make sure that that the npcs are far$$anonymous$$g or sleeping etc. at the right time when the player enters the scene, but I'm not sure how I'd get them to instantiate to right the place with the right equipment. NPCs have to get a tool from storage and then they find what to harvest based a manager script that records the locations of all the crops. They then move to the nearest crop and harvest until all the crops are harvested or it's time to stop. Perhaps there is too much detail in this design for a multi scene project.