// Update is called once per frame void Update() { //this.transform.Translate(new Vector2(direction.x * Random.Range(speedXMin, speedXMax), // direction.y * Random.Range(speedYMin, speedYMax))); PixelMover.Move(this.transform, direction.x * Random.Range(speedXMin, speedXMax), direction.y * Random.Range(speedYMin, speedYMax)); //if(animation.GetCurrentAnimatorStateInfo(0).IsName("FloorSmoke")) //{ // Destroy(gameObject); //} }
// Update is called once per frame void FixedUpdate() { /* * * Get direction from actor to player and apply speed to it * */ if (State == FOLLOW) { Vector2 pd = new Vector2(player.transform.position.x - this.transform.position.x, player.transform.position.y - this.transform.position.y); pd.Normalize(); velocity = new Vector2(pd.x * speed, pd.y * speed); } else { velocity = new Vector2(0, 0); } /* * * Apply Flocking Behaviour! * */ GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); Vector2 alignment = ComputeAlignment(enemies, this.gameObject); Vector2 cohesion = ComputeCohesion(enemies, this.gameObject); Vector2 separation = ComputeSeparation(enemies, this.gameObject); velocity.x += alignment.x * alignmentWeight + cohesion.x * cohesionWeight + separation.x * separationWeight; velocity.y += alignment.y * alignmentWeight + cohesion.y * cohesionWeight + separation.y * separationWeight; /* * * Set Direction of the actor based on it's veloity * */ direction.x = WolfMath.Sign(velocity.x); direction.y = WolfMath.Sign(velocity.y); PixelMover.Move(this.transform, velocity.x / 2, velocity.y / 2); SetAnimation(); }
private void moveActor() { //this.transform.Translate(velocity); PixelMover.Move(this.transform, velocity.x, velocity.y); }