- Home /
I solved it ;)
Releasing marbles at the right time
Howdy everyone, I have no idea what's going on here.
What I want to do is take an image of black/white pixels (the 'song') and release marbles on cue to play the song as the marbles hit the piano keys. What's happening, though, is the marbles don't drop at the right times, and their mistakes aren't random (the same thing happens every time I run the game.)
Here's a YouTube video for you to watch to better understand what's going on. https://youtu.be/Sw9JbhIB-Bc
What's most confusing about this is that the blue cubes you see in the video disappear/reappear each time a marble is supposed to be released. These test cubes go along with the song perfectly. The same function that calls for the cubes to disappear/reappear also tells a marble to be released, which means I have no idea how the mistake comes about.
Here's a picture of the "song" that plays from bottom to top, of course by looking at this it's obvious why the blue test cubes behave the way they do, and the test cubes also prove there's no compression issue and there's nothing wrong with how the song plays.
This image might be a bit confusing, so I'll explain. Every "tick" the machine plays a horizontal row going from bottom to top. If a pixel is white, it doesn't play. If it's black, it is supposed to release a marble. Once again, the function to play a key is called perfectly every time (as represented by the blue test cubes in the video) but the marbles don't release as they should.
So, can you tell me what might be going on? If you need to see anything else just let me know; I'd be more than happy to upload more videos or pictures, or just answer questions. Lastly, here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class arm_stopper : MonoBehaviour
{
GameObject marble = null;
//sets "marble" when it collides with the "stopper" (the player is also a marble)
void OnCollisionEnter (Collision c)
{
if (c.transform.tag == "marble" || c.transform.tag == "Player") {
marble = c.gameObject;
}
}
bool testCubeEnabled = true;
//this is called from the manager that plays the song. This is called perfectly every time.
void ReleaseMarble ()
{
if (marble) {
testCubeEnabled = !testCubeEnabled;
transform.GetChild(0).GetComponent<Renderer>().enabled = testCubeEnabled;
//layer 10 is no-collide with the stopper, meaning the marble should roll through the stopper.
marble.gameObject.layer = 10;
StartCoroutine(ReenableMarble (marble));
marble = null;
}
}
IEnumerator ReenableMarble (GameObject marble)
{
yield return new WaitForSeconds (.5f);
//makes the marble collide-able with the stopper, as it will cycle back around and be used again
marble.layer = 0;
}
}