Dev Diary 017: Match 3 Invaders, Bug Fixes and some new features

Matt Barton's picture

I'm back today with some bug fixes--thanks to Trip for helping me find the problem with the aliens not respawning after a restart. I also made a few other tweaks and added some new features, namely a brief (perhaps too brief?) period of invincibility after your ship respawns, and three new types of power-ups: extra life, speed boost, bonus points, and of course ever-popular cannon upgrade. I also took another person's advice and added a "color reminder" swatch just below the score. I'm still getting occasional missed matches. I went back through my code today and still don't know why that is happening. It seems to come in spurts; you can play several rounds without a hitch, but then get it two or three times in a row.

Unity Web Player | WebPlayer

Comments

TripHamer
TripHamer's picture
Offline
Joined: 07/31/2010
As far as missed matches

As far as missed matches go....hopefully it's not a sync issue. There is probably a rare instance that's not accounted for that causes it and/or the way the code is written....or the order it's written in.

n/a
Matt Barton
Matt Barton's picture
Offline
Joined: 01/16/2006
I'm pretty sure it is a sync

I'm pretty sure it is a sync issue. I just don't know enough about syncing works in Unity to fix the problem.

n/a
Matt Barton
Matt Barton's picture
Offline
Joined: 01/16/2006
In any case, I think the

In any case, I think the bug/glitch is rare enough not to be a deal breaker for a freebie. I wouldn't try to sell something like that, but it's starting to look like the problem is just simply beyond my technical ability to solve. I can either waste days, weeks, or months trying to figure it out until I burn out, or just work around it as a known bug--at least for the time being. My guess is that I'd need an expert (or at least someone with more experience) to actually look at my code and spot the problem.

Here's the relevant bit of code...This is in my script for the enemies:
int CheckBlockColor(GameObject TargetBlock)
{

RaycastHit hit;
int counterB = 0;
TargetBlock.tag="Marked";

// Check in all directions
if (Physics.Raycast(TargetBlock.transform.position,Vector3.left, out hit, ray_length))
{
if (hit.transform.tag == "Enemy")
if (hit.transform.GetComponent().mycolor == hitcolor)
{
hit.transform.tag = "Marked";
counterB++;
}
}
if (Physics.Raycast(TargetBlock.transform.position,Vector3.right, out hit, ray_length))
if (hit.transform.tag == "Enemy")
if (hit.transform.GetComponent().mycolor == hitcolor)
{
hit.transform.tag = "Marked";
counterB++;
}
if (Physics.Raycast(TargetBlock.transform.position,Vector3.up, out hit, ray_length))
if (hit.transform.tag == "Enemy")
if (hit.transform.GetComponent().mycolor == hitcolor)
{
hit.transform.tag = "Marked";
counterB++;
}
if (Physics.Raycast(TargetBlock.transform.position,Vector3.down, out hit, ray_length))
if (hit.transform.tag == "Enemy")
if (hit.transform.GetComponent().mycolor == hitcolor)
{
hit.transform.tag = "Marked";
counterB++;
}
return counterB;
}

This function gets called upon collision with projectiles and decide whether to change colors or blow up a match based on what it returns. For whatever reason, it sometimes returning 0 even if there is a matched color. Since it's not consistent (it works 90% of the time), I just don't get it. As far as I can tell, sometimes the raycasts just don't hit their targets.

n/a
TripHamer
TripHamer's picture
Offline
Joined: 07/31/2010
if you paste...

If you paste your code inbetween < pre > < /pre > it'll keep it's formatting....without the spaces between the <> of course.

n/a
TripHamer
TripHamer's picture
Offline
Joined: 07/31/2010
Even though you can leave out

Even though you can leave out some brackets in your if statements, you probably should put them in for clarity.


int CheckBlockColor(GameObject TargetBlock)
{
	RaycastHit hit;
	int counterB = 0;
	TargetBlock.tag = "Marked";

	// Check in all directions
	if (Physics.Raycast(TargetBlock.transform.position,Vector3.left, out hit, ray_length))
	{
		if (hit.transform.tag == "Enemy")
		{
			if (hit.transform.GetComponent().mycolor == hitcolor)
			{
				hit.transform.tag = "Marked";
				counterB++;
			}
		}	
	}

	if (Physics.Raycast(TargetBlock.transform.position,Vector3.right, out hit, ray_length))
	{
		if (hit.transform.tag == "Enemy")
		{
			if (hit.transform.GetComponent().mycolor == hitcolor)
			{
				hit.transform.tag = "Marked";
				counterB++;
			}
		}
	}

	if (Physics.Raycast(TargetBlock.transform.position,Vector3.up, out hit, ray_length))
	{
		if (hit.transform.tag == "Enemy")
		{
			if (hit.transform.GetComponent().mycolor == hitcolor)
			{
				hit.transform.tag = "Marked";
				counterB++;
			}
		}
	}
		
	if (Physics.Raycast(TargetBlock.transform.position,Vector3.down, out hit, ray_length))
	{
		if (hit.transform.tag == "Enemy")
		{
			if (hit.transform.GetComponent().mycolor == hitcolor)
			{
				hit.transform.tag = "Marked";
				counterB++;
			}
		}
	}		

	return counterB;
}

//This function gets called upon collision with projectiles and decide whether to change colors or
// blow up a match based on what it returns. For whatever reason, it sometimes returning 0 even if 
//there is a matched color. Since it's not consistent (it works 90% of the time), I just don't 
//get it. As far as I can tell, sometimes the raycasts just don't hit their targets.
 
 

n/a

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.