- Home /
How to divide a soccerpitch into regions
Hie I am trying to make a soccer game using unity3D. I have managed to load the soccer pitch, ball and the players when the game starts. My problem is I want to assign players to certain regions according to the team's formation. The problem is how do I divide my soccer pitch into these regions. I came up with a way of doing this but its not working correctly. The reasoning behind my method is I have a region which has a coordinate s its variable. In my SoccerPitch class I have a createRegion method which creates a singles region and a createRegions method which should create the regions all over the pitch. I am having problems in creating this. I am still new to unity3d and game development. Any form of help will be greatly appreciated
How are the players using this region information ? Do you need them to stay strictly inside a region or just "prefer" some positions ?
First thing that comes to $$anonymous$$d would be to have a 2D coordinate on the pitch for every player and have them run after the ball within a certain radius of their assigned spots. $$anonymous$$aybe to have them give up chasing the ball based on probability, and have the probability grow larger the farther they get from their spot.
thank you. I want to divide the pitch into regions .For me to dive the pitch into regions I have to know the dimensions of my soccer pitch, and then calculate these regions and store them in an array. I am having problems in getting these dimensions. I did some research and found out that I can use the Collider attached to my game object to get my bounds.Here is what I'm trying to do
//a region is a 2D rectengular shape where, with a center
public class Region : $$anonymous$$onoBehaviour {
private Vector2 topLeft;
private Vector2 topRight;
private Vector2 bottomLeft;
private Vector2 bottomRight;
private Vector2 center;
//constructor
Region(Vector2 topLeft,
Vector2 topRight,
Vector2 bottomLeft,
Vector2 bottomRight){
this.topLeft = topLeft;
this.topRight = topRight;
this.bottomLeft = bottomLeft;
this.bottomRight = bottomRight;
//calculate the center
this.center = new Vector2((topRight.x-topRight.x)/2, (bottomLeft.y- topLeft.y)/2);
}
}
The CreateRegion method uses a double for loop to calculate these regions.but it has to know the width and height of each region by using the length and width of the pitch(region_width = length_of_pitch/number_of_regions_horizontal, region_height = height_of_pitch/number_of_regions_vertical).This is where my problem is Here is the CreateRegions function inside Soccer$$anonymous$$ch class
//create regions for the game
public void CreateRegions(){
for (int x = 0; x < 6; x++)
{
for (int z = 0; z < 3; z++)
{
//still experimenting
}
}
}
i would use placeholder empty gameobjects and an array of their position so that you can move them for different formations on a preset pattern.
Answer by static_cast · Nov 25, 2014 at 04:59 PM
Try making an array with the positions they are supposed to be, then make them run to those positions. It doesn't help that you don't show any code.
Answer by andyblem · Nov 27, 2014 at 08:46 AM
I did it .I used empty game objects as my region(spot as such) added the soccerpitch as there parent. I used the mesh and the bounds to get the size of my pitch. Then used a double for loops to calculate the coordinates and populate them across the pitch
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do i create lines in scene view?? 1 Answer
Cube clips and falls through wall when held 0 Answers
Enemy only moves in a line 1 Answer