I'm trying to create a roguelike in the vein of Rogue Legacy, but I need to know how to not have enemies carry over from room to room. All enemies need to be idle and reset when you leave the room. I want to do this without changing the scene because that would be very memory intensive.
Here is an example:
https://youtu.be/B5jL25HgSIs
Bonus points if you know how to lock cinemachine to the room that you are in.
Yeah, I wouldn't recommend changing the scene as that takes more time (and all the GameObject instantiations can be avoided).
What I'd do is to have a single scene with all of my rooms, and determine in which room my character is by checking its position. If I detect it has moved to another room then I'd move the camera to render the next room, and in the same code I'd reset all the enemies of that room. At the same time I'd freeze all the enemies in the room I just moved from.
By the way, I feel this question, more than pertaining to Stack Overflow, pertains to Unity Answers. That one is specialized in Unity while here I rarely see a Unity-related question.
Related
I have been building a 2D sprite based game for which I want to have the player be able to customize their equipment. This means that although I am fine with drawing the content, I'd need to ensure animations in the game run fine on top of each other. For this, I have been preparing a game object with several children to account for the equipment:
Each of the children runs a single animation and should have to follow the player, which I accomplish by using transform.localPosition = Vector2.zero; on the Update of the script each takes, so they hook to the parent's pivot and follow the player. While this has worked for the most part, there are moments in which all of the objects are not synchronized and as such sometimes the parent object (the body) is seen where it shouldn't since the other game objects should render on top:
Aside from that, to make it easy for the children to follow the parent position I had made sprites which are all the same size, which risks me having to load a lot of transparent space per sprite.
Another problem that I just noticed as I'm trying to address the issue of loading too many useless pixels involves the positioning with other objects such as the Sword game object, which doesn't follow the player fully if I use sprites that are not perfect squares (see this question for details How to align sprites of smaller sizes to a moving gameobject sprite? and this one Sibling sprite doesn't appear to follow main GameObject sprite even when transform.position updates)
I tried to fix this by making the Sword a child of the Hero, but even then changing the position through a function that sets values to add on to transform values of the sword game object only change the position of it relative to the initial value. I attempted changing the pivot of the sword sprites to a custom value to guess where the center of it would align with the main game object and appear in the right position, but even that doesn't seem to work.
I'm kind of getting tired with my current process, as I have to rely on several animations for each of the game objects, both parent and children, so that these obey to different layers in a single animator (or in the case of the sword, a separate animator), all to ensure there is some synchronization that doesn't always occur:
I really don't mind the web that is turning out in what I'm doing, but the fact that I have to repeat it across multiple layers with no real guarantee that all the objects would appear right on top of each other due to the fact of having multiple animations playing, and loading multiple sprites with empty space is becoming more of a chore than enjoyment.
So I think I came up with a possible solution: If I could make a single animation for the whole equipment used at any given point (whether only wearing pants or wearing full equipment), then having this single animation could guarantee synchronization across parent and children without the need for animator layers or special functions to update position or worrying about pivots or square sprites if I can set the position of non-square sprites in the animation, with the downside that I would need to account for every single animation for each possible equipment variation (so if I had even 3 of each sword, pants, boots, etc. that would mean 3^6 animations) and make a more complex web of animator states. The only thing I'd be worried about in this case, however, would be the performance, if having too many animations for a player would affect how fast these load. But at the benefit of eliminating the other problems mentioned, my question boils down to this:
Is it better to have a single game object with animations that change multiple sprites across children game objects and a single animator that chooses states based on multiple variables, or game objects with multiple animations that change a single sprite for each, and a single or multiple animators with multiple layers that choose states based on multiple variables?
There isn't really a set answer for something like this. It really just depends on how good your/the players computer is when playing the game. Sorry if this isn't what you wanted.
I'm currently making a 2d platformer game with unity. I'm going to build game world with rooms (like in Hollow Knight and many other metroidvania games). So, my first idea is to have each room as a separate prefab with virtual camera and exits linked to other rooms on scene. And to have several scenes (smth like each scene contains a set of "thematic" rooms).
I have another idea but i'm not sure if it gonna work properly in terms of perfomance. The idea is simple - to have single game scene and instantiate\destroy game rooms dynamically and seamless. So the game will have current room and all adjacent rooms loaded (with some depth maybe, i.e. all adjacent rooms with depth R), when player changes room - some new rooms are instanciated and others destroyed. This feels like a good idea, cause after creating dynamic room system you can just concentrate on creating and linking rooms. But i'm afraid it can lead to some perfomance problems (i.e. game freezes when player moves from one room to another if there is a big enough room nearby). And i guess there can be a lot more unexpected problems.
So it's kind of open-type question. What do you think about this "dynamic" approach? Is it worth trying? If you have expirience building similar games, what design approach did you use?
Typically, creating and destroying objects in-game is a no due to performance issues.
From my high school game dev teacher, a better way to do it is to preload everything outside the camera, and just move needed resources into view as needed for a randomly generated scene.
If you're looking for a static scene, I would just preload everything that I need for that specific scene.
I have a question that is a little... complex
basically I want a gameObject (an enemy) "listen" to the sound of the player (footsteps, door opening, gunfire etc)
I could do this just fine by using:
>Collider[] hitColliders;
>hitColliders = Physics.OverlapSphere(transform.position, 10f,enemyLayer);
>
>for(int i=0;i<hitcolliders.Length;i++){}// Call Enemy Hear Player Function
However, the problem starts here:
I want the "sound" to be blocked by walls. At first, I thought I could use Physics.Linecast to do this. However, this means the sound could be blocked by a mere piece of pole, because Physics.Linecast only shoots a single, straight line.
What I want is player C could not hear anyone at all, but player A and B could still hear each other.
I hope you guys understand my question.
You could place the objects you want to block the soundwave on a specific layer. And just make the raycast ignore all other layers.
Leave all this Physic and other graphical stuff behind.
Create a separate logic for this behavior.
Create a big chess board (where x,y will be x,y position in you game) and add only sound-generators, sound-listeners and sound-obstacles.
Update this chess board each frame and create sounds, fly sounds, block sounds and listen to sounds and act appropriate as the real life actors.
This way you can add parameters to each obstacle, sound-generator and sound-listener so that all be configurable.
I am making a game using a combination of Blender and Unity and have hit a wall. I am trying to make it so a lamp flies off of a table and smashes against a wall once the player walks past a certain point in the map.
I am having a hard time with this. Any help is appreciated.
You need to break this up into little parts.
The first part is that once the player walks past a certain point you want to do something. To do this, look at http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
An on trigger event will let you run some code when an object collides with another object. In your case, when your player collides with a certain point in the game.
Next, inside that OnTriggerEvent, you want to fire the lamp off the table. To best do this, create a keyframe animation (or whatever you're most comfortable with) that animates the lamp to fly off the table. Lastly, play that animation in the trigger event. http://unity3d.com/learn/tutorials/modules/beginner/animation
To summarize, when the user hits a certain point, play an animation on the lamp.
I have a location consisting of several connected rooms and some enemies chasing me. But when bots are walking very close to walls I can see their hands passing through the walls, despite both bots and walls have colliders and enemies cannot go through them. Is there any way I can create a border or something to prevent it?
It sounds like #Heisenbug is probably correct.
I would attach a secondary collider to your model, most likely a box (for speedy processing) and call it personal_space. This way you can control how much space they give themselves from walls and such while still allowing them to get closer to the player and other special objects.