- Home /
What options are practical for returning a character to (0,0,0)?
In my game I have a very large world (Infinitely large for the sake of argument). The play style is a birds eye view hack and slash. The terrain is flat, there are no real hills or dips for rivers. I don't want to move the world while my character stays fixed in the center unless that is the best option. There can potentially be 100 different objects that the character can interact with in some manner (fighting, collecting, destroying, colliding against). My terrain is build up of "tiles". What I would like to do is, move the character and as it progresses load and unload different tiles, my problem is the size of the world. After my character is adventuring out at lets say (10,000, 0, 10,000) (which is farther than I would like to let it get), how can I bring it back to (0, 0, 0) with minimal visual hiccups? I have read about recreating the scene at (0, 0, 0) and then jumping the camera, but I didn't know if there were better options. This is a mobile game and I need to keep my active game object overhead as low as possible to allow for more content, however I am prepared to build around constraints like these.
Thanks for the advice and help.
I'm not sure if I have understand you, but, what if you try to change its position?
transform.localPosition = new Vector3(0,0,0);
that would work however I would need to change the position of everything in the scene to (0, 0, 0). Changing the position of that many objects can look glitchy. I would need to change the position of projectiles and monsters and landscaping so that when they all land at (0, 0, 0) the user has no idea I reset the scene to (0, 0, 0).
Have you tried to reload de scene? I think its not what you are looking for, but it could be another way.
Also you can use a foreach, move all objects inside an empty GO use the GO for apply this code:
Transform[] children = transform.GetComponentsInChildren<Transform>();
foreach (Transform child in children){
transform.localPosition = new Vector3(0,0,0);
}
Answer by scarletshark · May 06, 2015 at 02:19 PM
Parent all interactable objects underneath your world tiles, and asyncronously load a new tile as you reach the edge of your current world tile. When you reach the new tile, you could use the collision event to trigger its movement so you don't have to constantly be looking for if(transform.localPosition.x > 10000)
.
Then on the new world tile GameObject, you can put this script:
void OnCollisionEnter(Collision collision) {
if(collision.tag == "Player"){
transform.position -= collision.transform.position;
}
}
The only issue with this is if your character has a jumping or falling animation. Every time he lands, this will run. So perhaps you want to put box colliders on the edge of your world tile, and only run the script when the player interacts with them.