Group Group Group Group Group Group Group Group Group

How to detect when the player has filled a shape?

#1

In my game, the player is presented with a plane containing obstacles (orange / blue) and regions of empty space (white).

The player moves their green cube around the empty space, which instantiates a trail of green cubes behind it, painting the path they’ve travelled.

I need to detect when the player has painted all of the empty space, so that they can proceed to the next level.

public float speed = 10f;
private RaycastHit hit;
public GameObject paintcube;
float maxdistance = 0.51f;
bool moves;

private void FixedUpdate()
{
	Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 3, Color.green);
	if (Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward), out this.hit, maxdistance/*,layerMask*/))
    {
	    if (hit.collider.gameObject.tag == "myobstacle")
        {
            moves = false;                                                         
        }
		if(moves)
		{
			movepaint();
		}
	}
}	
public void movepaint()
{
    if (moves)
    {
		MyList.Add(Instantiate<GameObject>(paintcube, position, transform.rotation));
	}
}
#2

@rahulnaron Thanks very much for your question!

What is currently happening with your code above? The approach that comes to mind is to calculate the white space after the user stops movement, and see if a positive value is returned (or simply calculate the area that is covered by the cubes, and subtract it from the white space). Most likely this calculation would be done in a separate function which would pass in the area of the cubes, and return a bool of true/false indicating whether the white space still exists or not.

I hope this helps!

All the best.

#3

@syedfa thanks for suggetion i m still not solved this problem in my game can u give any referance for calculation for my programme because it is my pending game now i m work another game i m fresher can u give some calculation or navmesh reference so completed my game??