how to create a responsive scene - c#

I'm currently creating a 2D Android and iOS game using Unity3D engine. I'm testing the game on a nexus 5, and an iPhone 5s device. Everything until now is working fine and I am pretty happy with the result, but when I test that application on an iPad or a Samsung tablet all the objects in my game scene are not in the correct position anymore. Is this a common problem in Unity3D ?
I know I am missing something but I tried to do some research and what I found is only by changing the orthographic camera scale might fix this problem, but I found it as a big amount of code to write as my game have not only one scene but multiple scenes and every scene have it's own game objects.
Is there any other method to do, a good and simple work around for this problem?

It's all about setting the Anchors right.
If you're using the new UI System, make sure you anchor the objects where you want them to be, that's how you will achieve resolution independence.
For more information about anchoring, see this tutorial

Don't have separate scenes for separate devices. You can use the Screen object to check the height and width of your display. Then you can use this to set the orthographic size of your camera to something that makes everything visible as expected.

Update: I misunderstood your question, you say GameObject, i understand UI.
Please check this. I don't have this issue on my game. But when i try it with mac or windows machines, it is problematic. So maybe this can solve.
Other solution is more common which is you and Agumander say, change orthographic size of Camera.
This Is for UI
You can use Unity UI, and don't need to seperate. There are so many different resolution and density devices, you need to create so many scenes. So it is meanless separating scenes.
Unity UI has pixel based solutions which can be very helpfull for many density and resolution options. Forexample, It has VerticalLayoutGroup and HorizontalLayoutGroup for easy list like element visulation.
Most important thing is: Do you want to change UI for different screen size or resolutions? For example iPad has larger screen so user can be see more content. This change UX. Maybe you need to consider this.

Related

Surface light flickering on android devices

I have a problem with surface light flickering on android devices. I have tried everything I found online including changing near/far clipping planes of the camera, changing some quality settings like cascade shadows, turning shadows off/on, limiting to just one light source but I always get this problem. Everything looks OK in the editor.
Models in my game are made of multiple smaller 3d objects and it is always few of them that get this glitch.
This is how it looks:
You say that your models are made from multiple smaller models. Are you sure this is a lighting issue and not a z-fighting issue?
This can happen when two planes are in the exact same place, and which one is in the front can randomly change from frame to frame giving a flickering effect.
I could not find a credible Unity source explaining this issue, but here's a link to the Wikipedia on Z-fighting
As far as I know the only solution is to change your models to make sure the overlapping doesn't happen. Either my moving one of the planes down or deleting one of them.

FPS drop after few minutes in the Android game

I have made a very simple hypercasual game everything works fine but after some few minutes of gameplay, the fps goes from 60 to 50 even the phone gets heated up. Similar to this question. I tried profiling but just can't see anything off. Tried even removing some UI elements but still no luck. Tried various vsync settings. Also, I had used this to display the fps. Even without it, the lag can be seen. Even if I just open the game and do nothing then after 5 minutes the fps will become 50. If go back using the home button and re-enter the game then the fps becomes 60 again. Using unity 2018.2.6f1. Never experienced this behavior in my other Android games.
Basically it was a faulty custom vertex shader which was applied to a plane to change the background color which changed color over time. I had not used the mobile vertex color because I was not getting the desired output. But now I'll stick to the mobile one.
The two symptoms you observed are very much likely to be connected.
The phone might heat up, as you are using its full power, which in turn makes the throttling kick in, reducing the perform
I've had the EXACTLY same problem. I was trying to fix it for a very long time. You said something about faulty shaders you use. And this is the key to solve our problem.
I use a 2-color gradient as a BG, so I have to use a shader too. Due to the fact that I'm a total noob in the writing "shader-code", I have to find something in the Internet. And it was my biggest fail)
To fix the problem and remove this fps drop you should remove your gradient and shader attached to it from the scene. And try to find a more optimized shader for 2D-game (or you can always write your own one c:)

Unity - chat not on top of everything

So, I've been searching ALOT for this and I feel like I've tried pretty much everything, and still I'm coming up short.
The basic idea is to have a chat and also be able to have things in front of that chat window (lets say a draggable menu of sorts).
As a first thing I setup my chat as a GUI element. It works perfect.. word-wrapping and all, but it's always on top of everything else, so this doesn't really work for what I want to do.
The chat box is also scaling depending on your screen resolution.
I think the main issue is going to get it nicely word wrapped when NOT using GUI and I'm just all out of ideas.
Also wanted to state that the "menu" that's going over the chat is going to be containing gameobjects so it's not going to be another GUI element.
Can this even be done?
use GUI.depth=10 before drawing your chat window, and GUI.depth=5 after everything should appaer on top now.
From the documentation:
Set this to determine ordering when you have different scripts running simultaneously. GUI elements drawn with lower depth values will appear on top of elements with higher values (ie, you can think of the depth as "distance" from the camera).
if you dont want to do this.. determine order of drawing. Whatever gets drawn last is on top.
I understand at this stage it may be hard to do this, but its best to have one OnGUI active in your whole game/app. Having more than one deteriorates performance.
edit: to include scene renders on top of the GUI, you render your scene to a seperate camera (without gui) and have this camera render to texture. this texture can then be used in your gui by using for instance GUI.DrawTexture.

Collision detection not working as intended on all platforms

This question is going to sound odd because I really don't understand how this could be possible but here goes. I have some collision code for a 2D game of mine which works perfectly fine on Windows, Xbox, WP7, WP8. But for some odd reason the exact same code does not work when I run my game as a Windows 8 Metro App. What's even weirder is, the code works when I run the same project on my Surface but when I run it on my PC the bullets just go straight through the enemy. I don't think posting the code would be of any use since the code is identical where ever I use it and KNOW for a fact it works. If anyone knows how this is even possible please let me know. If you want me to post the code then let me know.
I'll explain a bit of what the code is doing:
Loops through all the player's bullets
Loops through all the enemies
If rectangle collision takes place
If per pixel collision takes place
Kill enemy, remove bullet etc.
The game runs fine as an XNA game on my PC which is the same PC I use to test it as a metro app.
This might be a computer speed problem. Does your game-loop work on a static timer, or do you throw updates/draws as fast as you can? It's possible the bullets aren't colliding because on one update they're in front of the enemy, and on the next they're behind. Try 'widening' the enemies or bullets as a debug - that may fix it. If this is the case, you may have to do some bullet updating within the update to make sure it hits all the locations in-between. and doesn't teleport through the enemies.
If you are using pixel values to test for collision, you may be trying to use DIP (device independent pixels) pixels thinking they are screen location pixels (something new with Metro, in fact, it's the default).
Set your app to run in simulation mode and set the sim's screen resolution to: 1366x768. Does it suddenly work correctly? if so, then it's a DIP issue.
Start here: http://msdn.microsoft.com/en-us/library/windows/desktop/ff684173(v=vs.85).aspx
notice the formula halfway down the page: DIPs = pixels / (DPI/96.0)

Building a robot simulator GUI using C#. Need some advice

I'm building a 2D robot simulator GUI for my autonomous robot vehicle.
I plan to keep the GUI simple. It consists of a vehicle (represented by a blue square picture), and some obstacles (cones, wall, etc, represented by yellow circle and red line respectively).
The vehicle must be able to move (as in the blue square must be able to move on the GUI) and be able to show its velocity and steering (float values) and its status (string) on the GUI.
I plan to use C# and Windows Forms to do this task, but I'm not sure if this is the right way to it. I remember using picture box a few years ago and I was not able to change the position of the picture box in real-time, or something weird like that.
Just wondering if you guys know a better way to do this. Is Windows Forms the way to go?
I've just moved from Ubuntu to Windows, so I am quite new at .Net stuff.
Here's what I've got so far http://imageshack.us/photo/my-images/708/guilo.png/
Future plans may dictate a change, but for what you describe Windows.Drawing should work fine. The only problem may be if you are using timers for updates, as it may not be fast enough for you.
So, how fast of an update rate do you need?
How much like a game framework will you actually need?
You may want to look at a tutorial like:
http://www.dreamincode.net/forums/topic/67275-the-wonders-of-systemdrawinggraphics/

Categories