SpriteKit gravity falling objects erratic jitters/choppiness - sprite-kit

I'm generating random falling SKSpriteNode objects in my scene. I noticed that sometimes the falling objects fall smoothly and sometimes they are jittery. It is more noticeable when I set the gravity at -4. I've been trying to figure out this erratic behavior but no success. However, I noticed also that the choppiness seems to disappear when I transition to a different scene and then transition back - sometimes I have to do it several times. The scene is running at a consistent 60fps even if the objects fill the screen. I've checked for areas where I might be bogging down the flow but even if I remove those possible areas it did not help. Has anyone experienced this behavior before? Thanks in advance.

Related

Unity Oculus Quest game stutters/lags when head is moved from side to side

Firstly, I've built for the Quest and checked the Unity profiler - everything seems good.
The weird thing is, when I move my head from side to side I don't see any framerate drops in the profiler but I see a noticeable stutter/lag in the headset. When my head is still or even just rotating, everything looks great, there's no stutter at all.
This stutter only occurs when I'm close to my UI and moving my head. When my head is static or rotating, it's all good. If I move back from the UI, there's no stutter either.
I don't think that it's an issue with too complex geometry or materials, as surely this would show up as a framerate drop in the profiler. I'm guessing that the camera movement is causing some kind of frame mismatch which (for some weird reason) isn't showing up in the profiler.
Does anybody have any ideas as to what might be causing this?
Well, I found the issue after narrowing the issue down to a specific set of GameObjects. It seems that the issue was being caused by a custom 'Dissolve' shader I was using. After setting the shaders back to 'standard' the problem went away! Weird...
This happens if your game FPS is lower than the device refresh rate.
For example if the headset is displaying 90 frames per second and your game is only able to render 70 frames per second, the headset needs to reuse a rendered frame every few frames.
When the game doesn't provide a rendered frame in time the device will just take the last rendered "image" and adjust it to the changed headset position and rotation. If it's a rotation change only, you will not notice, because the headset can easily just rotate the last image. But if it's also movement, the device can't simulate the difference of movement of close objects versus far objects on the image, so if you are moving an object close to a camera (e.g. your hand), it will stay at the same position for two frames (every few frames), which will make it look like it's stuttering.

Unity animations are twitchy when transitioning/blending. Any potential fix?

Video of issue in action: https://streamable.com/pkrog
The video linked above does a better job of explaining the issue than I could, but I'll give it a shot.
I have my walking/idle animations setup in a 2D Freeform Cartesian Blend Tree, which is working perfectly, aside from when I'm moving between transitions. So idle looks great, until I hold 'W' to move forward, then for the half second it's blending between idle and walking, my model gets very twitchy, then after it's done blending, it's smooth again. Same thing happens every time the Animator has to transition between different animations.
Any idea what could be causing this?
It might have to do with the fact that you update your camera in fixedUpdate and your animations are updated at the game normal update rate. So the different rate at which both your animations and your movement/camera/body updates makes it jittery.

Collision issue when player moves from one object to another

In unity 5 I am having an issue with certain collisions. I made a basic maze-like game where the player controls a cube across platforms (made from other cubes). In certain areas, two or more of the platforms touch so the player can get to different areas of the level. The problem with my collision happens at these intersections. The player will seem to get stuck for no reason and they would have to back up and get a running start in order to get to the other platform. I went through everything and made sure they are lined up perfectly in the unity editor but nothing seems to fix this.
Any advice would be greatly appreciated .
EDIT: all of my objects are using box colliders
A common (and good) practice is to use a Circle collider on the bottom of your character object in conjunction with a Box collider.
For Example:
While this will likely fix your issue, the source of the problem is probably using many small tiled cubes each with their own colliders. A large amount of tiled objects with colliders most likely cause performance and collision issues.

How to ensure sprites face the correct direction at all times in a 2D top down game. (logic)

I am making a multiplayer top down 2D game with 3d elements. All my movement, healthbars and basic functionality is working flawlessly even while hosted and playing on a server, node.js socket.io. However In this game it is possible to move the camera like in Realm of the mad god.
in case you are in doubt here is a video: https://youtu.be/4tdcxl3aZ0c?t=31s
This of course means that the players can end up being upside down with regards to each other and I cannot find a solution that works in all regards to make sure the sprites of the other players are always facing the correct direction with regards to their movement.
I have made several solution to this problem which cover most scenarios but while play testing other things we always end up noticing that the sprites sometimes face the wrong directions. So I am wondering if anyone has an answer, the logic, the fixing this problem.
Things I have tried:
Adding a gameobject to the camera to which all sprites asses their change in distance and determine their facing direction based off that information. (this leads to the players sometimes flipping erratically when the camera is moved and they as well are moving as sometimes they may be moving slower and there although moving left the camera approaches from the right and that flips them)
Adding a gameobject to the world which allows all sprites to have a fixed point to which they can measure their change in distance and therefore also know what direction to face (this worked somewhat better as they always know what direction they have to face, however once the player is upside down everything is inverted)
Emitting to the other players wether I am upside down or not in order to try to reinvert the above solution in the case I am upside down. (I could not find a good way to do this, and it got me thinking that this must be a problem people have fixed before many times and perhaps someone know of a good solution that works.)
thank you all for your input.
I seem to have found a solution for this issue that works decently well. Keeping in mind that I do not want to have the server being involved in this and I would rather have each individual sprite know its direction rather that have something heavy trying to determine this logic I came up with the following solution. May not be the best but it works. Still very keen to hear other solutions.
On my main character I have a switch case, which changes depending on the players rotation in the world. I need this switch case anyway for fixing (http://answers.unity3d.com/questions/1348301/trying-to-change-the-cameratransparencysortaxis-to.html?childToView=1348316#answer-1348316) that issue.
As the cases change I simply place the gameobject that I want the sprites to compare their distance to at 1 of 4 positions. YPos, YNeg, XPos, XNeg. Meaning that the sprite now determines its facing direction based on a gameobject that is placed in accordance with the Players position. without having to place it on the camera.
I will update if during further play tests this gives me trouble but thus far it works in the all the cases I need it to.
Still very willing to hear other solutions to this problem.
Thank you.

Sudden frame rate drops on mobile when instantiating/destroying?

I am currently working on a mobile game and I can't help but notice that whenever an object (an obstacle in my case) is instantiated or destroyed, I get a sudden FPS drop which is critical for my gameplay.
To help give an idea, I instantiate obstacles on top of my screen every 1.5 seconds, then I scroll them down. If the obstacles reaches the bottom of the screen already, I destroy them to prevent memory leaks/waste.
I'm still pretty new to Unity development. Am I on the right track though? What is a better solution to prevent this sudden frame rate drop?
Do you have any big / nested loops or complex processes going off as part of instantiation (Look at your awake/start methods)?
Regardless, look into object pooling as a better method to handle this type of thing.
For a basic example, instead of creating/destroying projectiles of a gun every time it's used, give that gun a "projectile pool" that creates n projectiles when the level loads. Then, when shooting, just set the projectile's position back to the gun and set the projectile as active. After impact, have the projectile deactivate (or after a few seconds if nothing is hit).