I'm making an XNA 4 game, and I want to create checkpoints for certain areas in my stage. I figured I could create a "ghost" object of the player object that would be created whenever the player reaches a checkpoint. And when you want to reload that checkpoint, you'll start to where that ghost player is.
As for now, I thought this would be an easy way to achieve this (although I think XML may be a better solution, but I've no idea on how to use that, yet). But the player has too many variables (health, stamina, ammo, bleeding timer, silver keys, golden keys, coins, infection, position, speed, angle, states [involve dying, infected, bleeding, burning, dodging, etc], I just thought that statemets like "continuep1 = p1;" (both are instances of the same object) would re-assign all the variables to the values that the other class contains, but when I tried to re-load "p1 = continuep1" it wouldn't work. It doesn't seem to do anything.
So I'm wondering, do I have to re-assign ALL the variables one by one? Should I start using XML? Or is there a way to assign all the variables without having to do it one by one? (I'm not asking for code, unless the last question is possible)
In my opinion I would say yes, start using xml. Don't worry about using xml, it's pretty simple once you get your head around it. A great way to learn would be to see your characters information displayed in xml format.
I think the most ideal option would be to serialize your game. So this involves storing the state of your character, the position it is at, the direction it is facing(which texture is currently loaded) and the stats(health, staming, bleeding etc).
With this you could reload your game from the last save when the player dies or when the game is next played. This would solve both cases.
This tutorial on making a top-down RPG game in Xna 4 is very good in my opinion and goes into good detail. Many of the techniques in this tutorial apply to more than just this genre and style of game.
http://xnagpa.net/xna4rpg.php
Part 11A(Game Editor) is the first part of a tutorial guiding the reader in making an editor for their game. With this Winforms project items, classes, quests etc can be added to the game and are stored as Xml files. At the bottom of page 6, and pages 7 and 8 outlines methods to serialize and deserialize your game.
In Part 11C(Game Editor), particularly at the bottom of page 9 and page 10. A save game method is introduced which serializes the game. You can also look at the new game and open game methods too.
These methods work with DataManager classes which store the items, classes etc in Dictionary's. This may be how you want to model your game information, if not the code in these guides may have to be altered to work with your solution.
I thought it best to provide my source for learning on this subject, rather than regurgitating it. I would recommend reading around this, not just the pages I've pointed to. Furthermore, in a later tutorial the serialization goes a step further and the files are stored in .xnb, which is a much more secure way to store information.
I hope this has helped and that you appreciate the guide in the right direction as opposed to just being given the answer. Besides, this isn't a task that would be solved in one method anyway.
Let me know how you get on and I'd be happy to help more.
Related
I'm working on a mod engine for a unity game. It is 2D based and stores all the level data in separate files ("level1", "level2") in the game data folder (I believe this is standard for unity). I am looking to be able to edit these in post to add/remove game objects in the scene. I wish to be able to do this programmatically in C#.
I've already had a look at the file in the hex editor, and it seems like this is possible (I can see basic game object data).
Currently im loading the scene then moving all objects around or instantiating new ones, but this is proving to be unstable because of the way the game handles objects.
If anyone could point me in the direction of how i would go about this, it would be greatly appreciated.
Update for those that are asking for additional info: Yes, by levels I mean scenes, unity saves them as “level0”, “level1”, etc
I am not the author of the game, the game was not designed with changing the scenes in mind, almost all of the interacatble objects have special riggers crafted to them, so in order to move them it requires me to be extremely careful or the game crashes.
From what you write it seems your separate files are actual Unity3D scenes. You should only have once scene and a system in place that reads and loads your data, for example from text files, then programmatically instantiate those object at run time.
I am trying to make a TopTrupms Card Game. I ended up with the cards and the Buttons of one player on the Stage. The second one is at the side. Because i want make a multiplayer game i have no concept how to move forward. Should i make the second Player also playable and than try to make it multiplayer or should i try to make it multiplayer now with the currentcard? (Code) I cant understand how it is possible to show different cards to different players at the same stage in multiplayer and i cant find a tutorial that shows this. Its always about 3d stuff where all player see the same things on the same stage. So i dont know which way to go. Please can anyone move me in the right direction, give me a hint or tell me how i should exactly do it!!! I dont know how to describe my project correct but i try. I made two different lists with shuffled cards and their attributes in it, parsed from a txt file. all the numbers are linked to different objects in the game that are a background image and different Buttons to choose the Value you wanna play against the card of the other player. Till now the second player can not vote and the first player is always at the turn. should i
Here is the Code and sorry for bad anotations, i am a absolut noob on this and just learning the basics of Unity and C# but i cant wrap my head around this Topic for any reason...
Please give me a hint!
It seems your question is more design based.
Read about the Entity-Component design pattern.
https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system
Basically think of an implementation like so, in your game you will have a list of Entities. Each Frame these entities will all update.
In the update function of your entities your entities will update all their components.
Your Player entities will have input components, but which input component will be decided at run time, either NetworkedInput, LocalInput, AiInput etc.
Got it!
The anwser is Network.isClient to make it multiplayer right away with the currentcard.
This is the way how i will do it. I jurst write every functions of the currentcard inside this if and els function for both players.
It should be the anwser i was searching for.
Thanks for the hints. They are very valuable for me.
#Ed Plunkett I hope i can present my next question more concrete and more on the point. It was hard for me to get a basic understanding of networking programming and i am so happy i got it now. Its always so easy afterwards.
In Unity3D the logic dictates that objects are not to be rendered unless in the field of view. This is obviously the way to go for optimization purposes. However, it still renders meshes that can not be seen by a player due to being occluded. I would like to solve this and was wondering if there was already a method to do so or if I had to do it myself.
Here's a picture to help illustrate my point.
So far my only real ideas are using the culling, but that still would be in a range not necessarily visible.
https://docs.unity3d.com/ScriptReference/Camera-layerCullDistances.html
I guess essentially what I need to know is how to do occlusion culling after a scene starts because the scene is generated, it's not premade.
For anyone who's interested, I asked the unity community
Answer by Bunny83 · 4 hours ago
No, that's not possible. At least not with the occlusion culling
system that Unity uses. The calculation which parts are visible from
which points is quite complicated and has to be precomputed in the
editor. So it won't work for procedurally generated levels.
You have to roll your own solution if you need something like that.
Just a few weeks (or month?) ago i implemented a VisPortals solution
similar to those used by Doom3 (basically how most ID Tech engines
work). It's more a prove of concept than a ready-to-use solution.
Usually i upload a webplayer demo onto my dropbox, however i just
realised that Dropbox finally prevented to directly view HTML pages
off my public folder. They now force a download of the page which
breaks everything. So if you want to try it, you have to download the
project.
Of course vis portals doesn't work in all situations. They are perfect
for closed environments which can be split nicely into seperate areas.
Of course this splitting into areas and the creation of the visportals
currently is done by hand. So you would need to automate this
yourself.
Be careful with static batching, it might break the system as each
area has to be seperate so it can be enabled / disabled seperately.
I'm designing an interactive book using Unity 3d.
I've some ideas of how to do this but I'm not sure if it's the right approach.
This interactive book contains around 15 pages, in which 12 of those pages contain apart from text, some animations that the user can trigger.
There are also sound effects (e.g. storm sounds, birds singing, etc) and a background soundtrack. It's very likely that a narrator voice would be present during the reading of the text, because it's intended to be an accessible application.(e.g. blind people could not read so they have to listen).
I've been thinking in the following design:
Create one scene per page. The idea is to represent each page through a scene, so we will have around 15 scenes.
Each scene will contain sound effects, audio tracks, narrator voice, text of the book and animations that can be triggered by the user.
We will concatenate the scenes, simulating the effect of book pages.
There are some issues, for example page transitions, up to now, we don't know if they want some 3d effect, but I could use Page Turn Curl or Page curler (Assets).
Any ideas? Is this a correct way of designing this app?
Thanks in advance!
this is quite a broad question but if I was approaching this I would start with the following...
Create a base class called interactive page...
An instance of an interactive page would be able to do the things you mentioned (play narration, play animations, display text, turn forward & backwards a page etc.)
I would then create another class with a list (probably called pages) which would be filled with all the customised instances of the pages I wanted to add.
I would devote a class to managing this list and the pages contained in it. If I wanted to add more books, that's when I would consider using another scene, but even then I would probably just stick to one.
There are many ways to do what you are talking about and the above is only one way off the top of my head.
Hope this helps :)
I'm new to Unity and I'm making a car racing Game. Now, I'm stuck at some point. I was looking for some solution of my problem, but couldn't succeed.
My problem is:
When I run my game on my phone, it sticks badly because whenever there are several buildings in front of the car camera, like one building behind another building, it lags. Reason for this is there are so many vertices and edges at that time, So the Car Camera is unable to capture all that stuff at same time.
How do I preload the 2nd Scene while loading 1st Scene?
I am using Unity free version.
In graphics programming, there is a common routine to simply don't draw objects that aren't in the field of view. I'm sure Unity can handle this. Check link: Unity description on this topic
I'm not hugely knowledgeable about Unity, but as a 3D modeller there's a bunch of things you can do to improve performance:
Create a simplified version of your buildings with fewer polygons for use when buildings are a long way away. A skyscraper, for example, can be as simple as a textured box.
If you've done that already, reduce the distance at which the simpler imposters are substituted for the complex versions.
Reduce the number of polygons by other means. A good example is if you've got a window ledge sticking out of the side of a building, don't try and make it an extension of the body. Instead, make it a separate box, delete the facet that won't be seen, and move it to intersect with the rest of the building.
Another good trick is to use bump maps or normal maps to approximate smaller features, rather than trying to model everything.
Opaqueness. Try not to have transparent windows in your buildings. It's computationally cheaper to make them just reflect the skybox or a suitably blurred reflection imposter. Also make sure that the material's shader is in Opaque mode, if it supports this.
You might also benefit a little from checking the 'Static' box on the game object, assuming that buildings aren't able to be moved (i.e. by smashing through them in a bulldozer).
Collision detection can also be a big drain. Be sure to use the simplest possible detection mesh you can - either a box, cylinder, sphere or a combination.