Big Game Project – Last Week

We’re on the last week of production but I think the game is in an okay state to showcase. I am implementing more sound effects and fixing bugs. Today I’ve fixed the building mode in which the player could place a new building anywhere, not considering other colliders. The actual bug was not that colliders weren’t checked, that was more a quick fix left from earlier to make sure that buildings could be built despite other problems with the collision checking.

I use the Unity function “Physics.CheckBox” to check if there are other colliders overlapping the collider of the building that’s being placed. The function takes the box as a Vector3 which I create using the variable “size” in the BoxCollider and dividing it by two since Physics.CheckBox takes in half the size of the box to check. I also pass in the rotation of the building to make sure the object rotates properly. The relevant part of the script can be seen below.

 

checkBuildPos = position + Vector3.up * 2;
Vector3 colliderSize = m_currentBuilding.constructionSiteCollider.size / 2;
bool hit = Physics.CheckBox(checkBuildPos,
     colliderSize,
     m_currentBuilding.transform.rotation,
     m_buildingLayerMask);
return !hit;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s