void Start() { _audioMaterial = new Material[8]; _colourOne = new Color[8]; _colourTwo = new Color[8]; for (int i = 0; i < 8; i++) { _colourOne[i] = _gradientOne.Evaluate((1.0f / 8.0f) * i); _colourTwo[i] = _gradientTwo.Evaluate((1.0f / 8.0f) * i); _audioMaterial[i] = new Material(_material); } _audioManager = FindObjectOfType <AudioManager>(); DebugHelper.debugHelper.IsValidObject(_audioManager); _flowField = GetComponent <FlowField>(); int bandCount = 0; for (int i = 0; i < _flowField.NumberOfParticles; i++) { //Create a more even distribution across the frequency bands int band = bandCount % 8; _flowField.ParticleMeshRenderers[i].material = _audioMaterial[band]; _flowField.Particles[i].AudioBand = band; bandCount++; } }
private void InitializeFlowField() { curFlowField = new FlowField(cellRadius, gridSize); curFlowField.CreateGrid(); print(curFlowField); gridDebug.SetFlowField(curFlowField); }
public void SetUp() { raw_tileData = new List <TileNode[, ]>(); mapHolder = this.GetComponent <MapBlockManager>(); mapHolder.OnAddMapComponent += OnAddBlock; _flowField = new FlowField(); }
public override void Redraw(float currentTime, float elapsedTime) { // selected vehicle (user can mouse click to select another) IVehicle selected = Demo.SelectedVehicle; Demo.UpdateCamera(elapsedTime, selected); Demo.GridUtility(Vector3.Zero); //Draw flow field const float RANGE = 50; const int SAMPLES = 25; for (int i = 0; i < SAMPLES; i++) { for (int j = 0; j < SAMPLES; j++) { Vector3 location = new Vector3(RANGE / SAMPLES * i - RANGE / 2, 0, RANGE / SAMPLES * j - RANGE / 2); var flow = FlowField.Sample(location); Annotations.Line(location, location + flow, Color.Black.ToVector3().FromXna()); } } // draw vehicles foreach (var vehicle in _followers) { vehicle.Draw(); } }
private void InitializeFlowField() { Debug.Log($"Generating grid of size: {gridSize.ToString()}"); curFlowField = new FlowField(cellRadius, gridSize); curFlowField.CreateGrid(); gridDebug.SetFlowField(curFlowField); }
public void Create_Grid() { FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10); testFlowField.CreateGrid(); testFlowField.grid.Length.Should().Be(100); }
// Use this for initialization void Start() { if (Instance == null) { Instance = this; } else if (Instance != this) { Destroy(gameObject); } CreateGroundPlane(); Debug.Log("Generating terrain..."); CreateTerrain(); Debug.Log("Done!"); Debug.Log("Separating terrain..."); CreateTerrainGroups(); Debug.Log("Done!"); CreateDebugShapes(); FlowField.InitUnitField(); FlowField.InitWallCostField(); debugMode = 0; }
public void Get_Cells_At_Relative_Pos_On_Corner_Cells() { FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10); testFlowField.CreateGrid(); Vector2Int originCellIndex1 = new Vector2Int(0, 0); Vector2Int originCellIndex2 = new Vector2Int(9, 9); List <Cell> neighborCells1 = testFlowField.GetNeighborCells(originCellIndex1, GridDirection.CardinalAndIntercardinalDirections); List <Cell> neighborCells2 = testFlowField.GetNeighborCells(originCellIndex2, GridDirection.CardinalAndIntercardinalDirections); List <Cell> expectedCells1 = new List <Cell>(); expectedCells1.Add(testFlowField.grid[0, 1]); expectedCells1.Add(testFlowField.grid[1, 1]); expectedCells1.Add(testFlowField.grid[1, 0]); List <Cell> expectedCells2 = new List <Cell>(); expectedCells2.Add(testFlowField.grid[9, 8]); expectedCells2.Add(testFlowField.grid[8, 8]); expectedCells2.Add(testFlowField.grid[8, 9]); neighborCells1.Should().BeEquivalentTo(expectedCells1); neighborCells2.Should().BeEquivalentTo(neighborCells2); }
public void Create(Tile destination, IntegrationField integrationField, FlowField flowField, int key) { Destination = destination; IntegrationField = integrationField; FlowField = flowField; Key = key; }
//Generate a flowfield texture private Texture GenerateFlowFieldTexture(float[,] flowField, bool[,] isObstacle, bool isBlackWhite) { //Assume the flow field is always square int mapWidth = flowField.GetLength(0); //Create a texture on which we will display the information Texture2D texture = GenerateNewDebugTexture(mapWidth); //Debug flow field by changing the color of the cells //To display the grid with a grayscale, we need the max distance to the node furthest away float maxDistance = FlowField.GetMaxDistance(flowField); //Generate the colors //More efficient to generate the colors once and then add the array to the texture Color[] colors = new Color[mapWidth * mapWidth]; for (int x = 0; x < mapWidth; x++) { for (int z = 0; z < mapWidth; z++) { //Default, meaning unreachable cell Color thisColor = Color.blue; float distance = flowField[x, z]; if (isObstacle[x, z]) { thisColor = Color.black; } //If this is not an obstacle or a cell that was unreachable in the flowfield else if (distance < float.MaxValue) { float rgb = 1f - (distance / maxDistance); if (isBlackWhite) { thisColor = new Vector4(rgb, rgb, rgb, 1.0f); } //Red-green scale else { thisColor = new Vector4(1f - rgb, rgb, 0f, 1.0f); } } colors[z * mapWidth + x] = thisColor; } } //Add the colors to the texture texture.SetPixels(colors); texture.Apply(); return(texture); }
private void InitializeFlowField() { team1_flowfield = new FlowField(cellRadius, gridSize); team1_flowfield.CreateGrid(); team2_flowfield = new FlowField(cellRadius, gridSize); team2_flowfield.CreateGrid(); gridDebug.SetFlowField(team1_flowfield); }
// Use this for initialization public override void Start() { base.Start(); flowFieldFollowers = manager.GetComponent <ExerciseManager>().flowFieldFollowers; flowScript = manager.GetComponent <FlowField>(); obstacles = manager.GetComponent <ExerciseManager>().obstacles; }
public Vector3 Flow(FlowField flow) { m_dv = Vector3.zero; m_dv = flow.GetFlowDirection(transform.position) * maxSpeed; m_dv.y = 0; return(m_dv); }
// Update is called once per frame void Update() { if (Input.GetMouseButton(1)) { foreach (KeyValuePair <int, GameObject> pair in selected) { //Will need to change this - each unit will need to store their own flow field //Make a new GridController? //If we make a new controller gotta make sure we set the x and the y //gridController.gridSize.x = 50; //gridController.gridSize.y = 50; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); //If it hits something if (Physics.Raycast(ray, out hit, 50000.0f, 1 << 8)) { gridController = GetComponent <GridController>(); GameObject gameobj = pair.Value; AIBehaviour behaviour = gameobj.GetComponent <AIBehaviour>(); //Flow field handling flowfield = gridController.InitializeFlowField(hit.point); Unit unit = gameobj.GetComponent <Unit>(); ///Don't like this unit.ai.finalDest = hit.point; //unit.ai.gridController = gridController; unit.ai.curFlowField = flowfield; //behaviour.dest = Vector3.zero; //behaviour.target = null; unit.state = Unit.State.moving; //behaviour.stop(); //behaviour.dest = hit.point; } } } }
private void InitAPI() { TileHelp.Init(this); SectorHelp.Init(this); AStar.Init(this); FlowField.Init(this); JumpFlowFiled.Init(this); IggPathFinder.Init(this); MapChangeManger.Init(this); }
public void StartMoving(FlowField FF) { MyField = FF; if (!ismoving) { Arrived = false; ismoving = true; StartCoroutine(Transverse()); } }
//Probably want to put this somewhere better private FlowField genFlowField(Vector3 desti) { gridController = sys.GetComponent <GridController>(); FlowField flowfield = gridController.InitializeFlowField(desti); return(flowfield); }
public FactoryBot(Vector2Int myTile) { position = new Vector2(myTile.x + Random.Range(-.5f, .5f), myTile.y + Random.Range(-.5f, .5f)); radius = .15f; hitCount = 0; navigator = null; targetCrafter = null; movingToResource = false; holdingResource = false; }
public FactoryBot(Vector2 myPosition) { position = myPosition; radius = .15f; hitCount = 0; navigator = null; targetCrafter = null; movingToResource = false; holdingResource = false; }
private void Awake() { selfUnit = GetComponent <Unit>(); selfRigidbody = selfUnit.selfRigidbody; selfCollider = selfUnit.selfCollider; UnitSpawner spawner = GetComponentInParent <UnitSpawner>(); map = spawner.map; flowField = spawner.flowField; }
public void Test_Getting_Cell_From_World_Position_Off_Grid_Max() { FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10); testFlowField.CreateGrid(); Vector3 worldPos = new Vector3(100f, 0, 100f); Cell testCell = testFlowField.GetCellFromWorldPos(worldPos); Cell expectedCell = testFlowField.grid[9, 9]; testCell.Should().Be(expectedCell); }
/* * //New Additions * public float current_temp; * public float initial_temp = 100f; * float lcl; * public float dewpoint = 40f;*/ public void constructVehicle(float ms, float mf, FlowField flow) { //r = 3.0f; maxspeed = ms; maxforce = mf; acceleration = Vector3.zero; velocity = Vector3.zero; flowfield = flow;/* * current_temp = initial_temp; * lcl = (initial_temp - dewpoint) / 8.3f;*/ }
// Implementing Reynolds' flow field following algorithm // http://www.red3d.com/cwr/steer/FlowFollow.html public void follow(FlowField flow) { // What is the vector at that spot in the flow field? Vector3 desired = flow.lookup(this.gameObject.transform.localPosition); // Scale it up by maxspeed desired *= maxspeed; // Steering is desired minus velocity Vector3 steer = desired - velocity; steer = Vector3.ClampMagnitude(steer, maxforce); ApplyForce(steer); }
public void Check_Walkable_Cell() { FlowField testFlowField = A.FlowField.WithCellRadius(0.5f).WithSize(10, 10); testFlowField.CreateGrid(); Cell testCell = testFlowField.grid[5, 5]; Cell destinationCell = testFlowField.grid[0, 0]; testFlowField.CreateIntegrationField(destinationCell); testCell.bestCost.Should().NotBe(ushort.MaxValue); }
public void setFlowField(FlowField flowField) { if (this.flowField == null) { FlowField.AddUnit(this.transform.position, this.separationRadius, this.separationFactor); } this.flowField = flowField; //this.flowField.AddSeparation( this.transform.position, this.separationRadius, this.separationFactor ); //this.flowField.AddSeparation( this.transform.position, this.cohesionRadius, this.cohesionFactor ); }
//Todo - Probably move this to the flowfield script and pull requests from there public void moveTo(Vector3 destination) { moving = true; FlowField ff = genFlowField(destination); //Move to a gold node moveai.finalDest = destination; //worker.ai.finalDest = dest; moveai.curFlowField = ff; //worker.ai.curFlowField = flowfield; moveai.state = moveAI.State.Moving; //worker.state = Worker.State.moving; }
void Update() { // get a desiredVelocity from the flow field, based on our current position Vector3 desiredVelocity = FlowField.GetFlowAtPos(transform.position); // change our velocity velocity += (desiredVelocity - velocity) * 0.25f; // make sure we don't take off velocity.y = 0; // update our position transform.position = transform.position + velocity; }
//FOLLOW FLOW FIELDS public Vector3 FollowField(Vector3 position) { GameObject target = GameObject.Find("Plane"); FlowField script = target.GetComponent <FlowField>(); position += script.GetFlowDirection(position); Vector3 desired = position - vehiclePosition; desired.Normalize(); desired = desired * maxSpeed; Vector3 steeringForce = desired - velocity; return(steeringForce); }
public void Awake() { btn_generate.onClick.AddListener(GenerateCubeMap); btn_setend.onClick.AddListener(SetEnd); btn_setstart.onClick.AddListener(SetStart); btn_ff.onClick.AddListener(GenerateFlowField); btn_go.onClick.AddListener(GoFF); ff = new FlowField(); //left, leftup, up, rightup, right, rightdown, down, leftdown direction = new Direction[8] { new Direction(-1, 0), new Direction(0, 1), new Direction(1, 0), new Direction(0, -1), new Direction(-1, 1), new Direction(1, 1), new Direction(1, -1), new Direction(-1, -1) }; }
public static FlowFieldNode[,] GenerateFlowField(Map map, IntVector2 targetPos) { //The final flow field will be stored here, so init it FlowFieldNode[,] nodesArray = new FlowFieldNode[map.MapWidth, map.MapWidth]; for (int x = 0; x < map.MapWidth; x++) { for (int z = 0; z < map.MapWidth; z++) { bool isWalkable = !map.cellData[x, z].isObstacleInCell; //bool isWalkable = true; FlowFieldNode node = new FlowFieldNode(isWalkable, map.cellData[x, z].centerPos, new IntVector2(x, z)); nodesArray[x, z] = node; } } //A flow field can have several start nodes List <FlowFieldNode> startNodes = new List <FlowFieldNode>(); //To a single target //startNodes.Add(nodesArray[targetPos.x, targetPos.z]); //To all obstacles for (int x = 0; x < map.MapWidth; x++) { for (int z = 0; z < map.MapWidth; z++) { if (map.cellData[x, z].isObstacleInCell) { startNodes.Add(nodesArray[x, z]); } } } //Generate the flow field FlowField.Generate(startNodes, nodesArray, includeCorners: true); //Debug.Log("Distance flow field: " + nodesArray[targetPos.x, targetPos.z].totalCostFlowField); //Debug.Log("Distance flow field: " + nodesArray[0, 0].totalCostFlowField); return(nodesArray); }
public Vector3 Flow( FlowField flow ) { m_dv = Vector3.zero; m_dv = flow.GetFlowDirection( transform.position ) * maxSpeed; m_dv.y = 0; return m_dv; }