Problem in Pillars Generation for Flappy Bird
https://preview.redd.it/zpnrc2nsduyd1.png?width=153&format=png&auto=webp&s=a1356b9cc33c4b86baf99c3e89502cda83d9b1b1
I am at the start of my Gamedev Journey and am trying to recreate Flappy bird and for some reason, the pillars are generating like this.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class MovingPillar : MonoBehaviour
{
SerializeField Vector3 startPos;
SerializeField float endPos;
SerializeField float waitTime = 2f;
SerializeField GameObject pillar;
SerializeField float pillarVelocity = 1f;
Rigidbody2D pillarRB;
bool Death = false;
void Awake()
{
pillarRB = GetComponent<Rigidbody2D>();
}
void Start()
{
pillarRB.velocity = new Vector2(-pillarVelocity, 0);
StartCoroutine(GeneratePillars());
}
void Update()
{
if (transform.position.x <= endPos)
{
Destroy(pillar);
}
}
IEnumerator GeneratePillars()
{
while (Death == false)
{
yield return new WaitForSecondsRealtime(waitTime);
GameObject pillarClone = Instantiate(pillar, startPos, Quaternion.identity);
Rigidbody2D pillarRBClone = pillarClone.GetComponent<Rigidbody2D>();
pillarRBClone.velocity = new Vector2(-pillarVelocity, 0);
// Wait for the pillar to reach the end position and then destroy it
float distanceToTravel = Mathf.Abs(endPos - startPos.x);
float travelTime = distanceToTravel / pillarVelocity;
yield return new WaitForSecondsRealtime(travelTime);
Destroy(pillarClone);
}
}
>This is the code and I am unable to fix the issue. Would appreciate some suggestions.
https://redd.it/1gj9c7y
@r_Unity3D
https://preview.redd.it/zpnrc2nsduyd1.png?width=153&format=png&auto=webp&s=a1356b9cc33c4b86baf99c3e89502cda83d9b1b1
I am at the start of my Gamedev Journey and am trying to recreate Flappy bird and for some reason, the pillars are generating like this.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class MovingPillar : MonoBehaviour
{
SerializeField Vector3 startPos;
SerializeField float endPos;
SerializeField float waitTime = 2f;
SerializeField GameObject pillar;
SerializeField float pillarVelocity = 1f;
Rigidbody2D pillarRB;
bool Death = false;
void Awake()
{
pillarRB = GetComponent<Rigidbody2D>();
}
void Start()
{
pillarRB.velocity = new Vector2(-pillarVelocity, 0);
StartCoroutine(GeneratePillars());
}
void Update()
{
if (transform.position.x <= endPos)
{
Destroy(pillar);
}
}
IEnumerator GeneratePillars()
{
while (Death == false)
{
yield return new WaitForSecondsRealtime(waitTime);
GameObject pillarClone = Instantiate(pillar, startPos, Quaternion.identity);
Rigidbody2D pillarRBClone = pillarClone.GetComponent<Rigidbody2D>();
pillarRBClone.velocity = new Vector2(-pillarVelocity, 0);
// Wait for the pillar to reach the end position and then destroy it
float distanceToTravel = Mathf.Abs(endPos - startPos.x);
float travelTime = distanceToTravel / pillarVelocity;
yield return new WaitForSecondsRealtime(travelTime);
Destroy(pillarClone);
}
}
>This is the code and I am unable to fix the issue. Would appreciate some suggestions.
https://redd.it/1gj9c7y
@r_Unity3D
How we cut down our Domain Reload from 25s -> 6s
We, like probably most of you, also hate waiting for noscript compilation & domain reloading. Making a minor change and waiting for that long sucks. So we (mostly my colleague) looked into what we had to do to make it better. Note that this worked for us, YMMV.
###Buy a better CPU
Throwing money at the problem solves some of it. We upgraded one of our office PCs to a 12700K and cut off a decent chunk for that PC (iirc it cut down the time from like 32s to 25s for him).
###Assembly Definitions
The official Unity response to this problem is mostly "use assembly definitions". And you probably should do that where applicable. Most (all?) of your plugins probably already use them. Other than that we only use 3: Some editor noscripts, our tests and everything else. We probably could've done that better but I'm not gonna spend a month rewriting half our codebase in the hopes to shave off a second or 2.
###Domain Reload
The core of this info comes from 2 articles:
1. https://johnaustin.io/articles/2020/domain-reloads-in-unity
2. https://blog.s-schoener.com/2023-08-16-why-your-unity-project-is-slow/
And here's the profilers we used:
1. https://openupm.com/packages/com.needle.compilation-visualizer/
2. https://openupm.com/packages/com.unity.editoriterationprofiler/
3. https://github.com/pschraut/UnityHeapExplorer
4. https://github.com/Unity-Technologies/ProjectAuditor
I recommend reading both articles, though the 2nd article helped me most. Make sure you go through the profilers and actually look at the data before you start tinkering. So what actually worked for us?
We got rid of most serializable data. Yep, that's about it. We have quite a few lists that we generate on startup and marking them as NonSerialized was like 95% of our improvements. We also marked (almost) everything that was shown in the inspector as such and got rid of a bunch of Serializable attributes on classes that didn't need it.
We tend to only use the inspector for debugging purposes anyway so that worked for us. Even marking public & private variables/properties that were not part of a MonoBehaviour as NonSerialized showed improvements, minor as they were.
###HotReload
Yeah it comes up often and I've had mixed results. It only works like half the time for me (or less?) but that's still time saved when it does work. There's a list on his site on what it works for (here: https://hotreload.net/faq), if you're curious.
If anyone has any other tips on this, would love to hear em!
https://redd.it/1gjcp9l
@r_Unity3D
We, like probably most of you, also hate waiting for noscript compilation & domain reloading. Making a minor change and waiting for that long sucks. So we (mostly my colleague) looked into what we had to do to make it better. Note that this worked for us, YMMV.
###Buy a better CPU
Throwing money at the problem solves some of it. We upgraded one of our office PCs to a 12700K and cut off a decent chunk for that PC (iirc it cut down the time from like 32s to 25s for him).
###Assembly Definitions
The official Unity response to this problem is mostly "use assembly definitions". And you probably should do that where applicable. Most (all?) of your plugins probably already use them. Other than that we only use 3: Some editor noscripts, our tests and everything else. We probably could've done that better but I'm not gonna spend a month rewriting half our codebase in the hopes to shave off a second or 2.
###Domain Reload
The core of this info comes from 2 articles:
1. https://johnaustin.io/articles/2020/domain-reloads-in-unity
2. https://blog.s-schoener.com/2023-08-16-why-your-unity-project-is-slow/
And here's the profilers we used:
1. https://openupm.com/packages/com.needle.compilation-visualizer/
2. https://openupm.com/packages/com.unity.editoriterationprofiler/
3. https://github.com/pschraut/UnityHeapExplorer
4. https://github.com/Unity-Technologies/ProjectAuditor
I recommend reading both articles, though the 2nd article helped me most. Make sure you go through the profilers and actually look at the data before you start tinkering. So what actually worked for us?
We got rid of most serializable data. Yep, that's about it. We have quite a few lists that we generate on startup and marking them as NonSerialized was like 95% of our improvements. We also marked (almost) everything that was shown in the inspector as such and got rid of a bunch of Serializable attributes on classes that didn't need it.
We tend to only use the inspector for debugging purposes anyway so that worked for us. Even marking public & private variables/properties that were not part of a MonoBehaviour as NonSerialized showed improvements, minor as they were.
###HotReload
Yeah it comes up often and I've had mixed results. It only works like half the time for me (or less?) but that's still time saved when it does work. There's a list on his site on what it works for (here: https://hotreload.net/faq), if you're curious.
If anyone has any other tips on this, would love to hear em!
https://redd.it/1gjcp9l
@r_Unity3D
John Austin
Fast Domain Reloads in Unity — John Austin
What are the main components of the Domain Reload, and how can we achieve those golden 5 second iteration times?
This media is not supported in your browser
VIEW IN TELEGRAM
Boss Snake! Climb high and strike when the giant snake's head is within reach!
https://redd.it/1gjj1r0
@r_Unity3D
https://redd.it/1gjj1r0
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
We Created a Dynamic Gesture Recognition Tool for Unity – Perfect for Interactive Applications!
https://redd.it/1gjcl19
@r_Unity3D
https://redd.it/1gjcl19
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
We're working on our survival game. Where would you guess our game is set? Which country and region? Virtual high five to those who find the right answer!
https://redd.it/1gjk0ok
@r_Unity3D
https://redd.it/1gjk0ok
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
working on a dazed effect for when you touch any corrupted surface.
https://redd.it/1gjkpnm
@r_Unity3D
https://redd.it/1gjkpnm
@r_Unity3D
Is it ok to have many prefabs instantiated in one scene?
https://preview.redd.it/635mklamyxyd1.png?width=833&format=png&auto=webp&s=606a3a5efeb678882d57f40e9c5ab59b8509a3d4
this is obviously just for level design and still in debug stage. I will use a Level loader later with dependency injection where I plan to instantiate chunks one at a time.
But maybe there is something I could use to group prefabs/game objects. Something like a sprite atlas that unity wants you to use for performance and clarity but I haven't heard of yet.
Thanks for any help.
https://redd.it/1gjnxk2
@r_Unity3D
https://preview.redd.it/635mklamyxyd1.png?width=833&format=png&auto=webp&s=606a3a5efeb678882d57f40e9c5ab59b8509a3d4
this is obviously just for level design and still in debug stage. I will use a Level loader later with dependency injection where I plan to instantiate chunks one at a time.
But maybe there is something I could use to group prefabs/game objects. Something like a sprite atlas that unity wants you to use for performance and clarity but I haven't heard of yet.
Thanks for any help.
https://redd.it/1gjnxk2
@r_Unity3D
Me and my friends made WievFinder and Rusty Laked inspired Puzzle Game in a small game jam. Take photos of objects , place them and escape from the house.
https://redd.it/1gjrm3v
@r_Unity3D
https://redd.it/1gjrm3v
@r_Unity3D
Reddit
From the Unity2D community on Reddit: Me and my friends made WievFinder and Rusty Laked inspired Puzzle Game in a small game jam.…
Explore this post and more from the Unity2D community
Is the new input system worth it?
I noticed the vast majority of tutorials use the old input system. Every time I try to do something I find tutorials that use the old one and I can never find stuff with the new one, it makes programming (and learning) much harder…
Is it worth it ?
https://redd.it/1gjsf9h
@r_Unity3D
I noticed the vast majority of tutorials use the old input system. Every time I try to do something I find tutorials that use the old one and I can never find stuff with the new one, it makes programming (and learning) much harder…
Is it worth it ?
https://redd.it/1gjsf9h
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community