// do the move computation
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 flockCenter       = ComputeFlockCenter(allyPositions.Values);
        float   distToFlockCenter = Vector3.Distance(flockCenter, this.transform.position);

        if (distToFlockCenter <= SeperationRadius) // to close spread out
        {
            Vector3 seperation    = ComputeSeperation(allyPositions.Values);
            Vector3 resultingMove = seperation;
            resultingMove.Normalize();
            unitMover.Move(resultingMove);
        }
        else if (distToFlockCenter <= DesiredRadiusToPlayer) // just right hang out
        {
            unitMover.Move(Vector3.zero);
        }
        else // flock
        {
            Vector3 allignment = ComputeAlignment(allyPositions.Values);
            Vector3 cohesion   = ComputeCohesion(allyPositions.Values);
            Vector3 seperation = ComputeSeperation(allyPositions.Values);

            Vector3 resultingMove = (allignment * allignmentPercent) + (cohesion * cohesionPercent) + (seperation * seperationPercent);
            resultingMove.Normalize();

            unitMover.Move(resultingMove);
        }
    }
    // do the move computation
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 flockCenter       = ComputeFlockCenter(allyPositions.Values);
        float   distToFlockCenter = Vector3.Distance(flockCenter, this.transform.position);

        if (distToFlockCenter <= SeperationRadius) // just right hang out
        {
            unitMover.Move(Vector3.zero);
        }
        else // flock
        {
            Vector3 resultingMove = ComputeFLockingMove(SeperationRadius);
            unitMover.Move(resultingMove);
        }
    }
Beispiel #3
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 dir = beelineTarget.transform.position - this.transform.position;

        dir.Normalize();
        unitMover.Move(dir);
    }
Beispiel #4
0
    void Update()
    {
        if (target != null)
        {
            movement = (target.position - transform.position).normalized;
            mover.Move(movement);
            if (anim.runtimeAnimatorController != null)
            {
                anim.SetFloat("X", movement.x);
                anim.SetFloat("Y", movement.y);
                anim.SetFloat("Speed", movement.magnitude);
            }
//			Vector3 targetDir  = transform.position + (movement * moveSpeed * Time.deltaTime);//paranthesis for clarity
//			transform.position = Vector3.MoveTowards(transform.position,targetDir,1f);
        }
    }
Beispiel #5
0
    void Update()
    {
        if (unitModel.IsDead)
        {
            return;
        }

        float h_axis    = Input.GetAxisRaw("Horizontal");
        float v_axis    = Input.GetAxisRaw("Vertical");
        bool  useRevive = Input.GetButtonDown("Revive");
        bool  usePotion = Input.GetButtonDown("Potion");

        Quaternion camRot = Quaternion.AngleAxis(gameCamera.transform.rotation.eulerAngles.y, Vector3.up);

        unitMover.Move(camRot * new Vector3(h_axis, 0f, v_axis));

        if (useRevive && unitModel.mana.amount >= reviveManaCost && revivableCorpses.Count > 0)
        {
            UnitCorpse closestCorpse = null;
            float      closestDist   = -1f;

            foreach (GameObject corpse in revivableCorpses)
            {
                UnitCorpse unitCorpse = corpse.GetComponent <UnitCorpse>();
                if (!unitCorpse.CanRevive)
                {
                    continue;
                }

                float dist = (corpse.transform.position - transform.position).magnitude;

                if (closestCorpse == null || dist < closestDist)
                {
                    closestCorpse = unitCorpse;
                    closestDist   = dist;
                }
            }

            if (closestCorpse != null && closestCorpse.Revive())
            {
                unitModel.TryDrainMana(reviveManaCost);
                revivableCorpses.Remove(closestCorpse.gameObject);
            }
        }
    }
Beispiel #6
0
    void Update()
    {
        float   lastInputX = Input.GetAxis("Horizontal");
        float   lastInputY = Input.GetAxis("Vertical");
        Vector3 mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);

//		float lastInputScroll = Input.GetAxis("Mouse ScrollWheel");
//		if(lastInputScroll>0f || lastInputScroll<0f)
//		{
//			Camera.main.orthographicSize -= lastInputScroll* scrollSpeed;
//			Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, minFOV, maxFOV);
//		}
//
        if (lastInputX != 0f || lastInputY != 0f)
        {
            Vector2 movement = new Vector2(lastInputX, lastInputY);
            mover.Move(new Vector3(lastInputX, lastInputY));
//			anim.SetFloat("X",lastInputX);
//			anim.SetFloat("Y",lastInputY);
//			anim.SetFloat("Speed", movement.magnitude);
        }

        if (Input.GetMouseButton(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100f, mask))
            {
                Vector3 dir = hit.point - transform.position;
                dir = dir / dir.magnitude;
                myWeapon.PrimaryAttack(dir);
            }
        }
        if (Input.GetMouseButtonUp(1))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 20f, mask))
            {
                Vector3 dir = hit.point - transform.position;
                dir = dir / dir.magnitude;
                myWeapon.SecondaryAttack(dir);
            }
        }
    }
Beispiel #7
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        // wander randomly for short distances
        targetMoveTimer = Mathf.MoveTowards(targetMoveTimer, 0f, Time.deltaTime);
        if (targetMoveTimer == 0f)
        {
            // Pick new target position
            targetMovePoint = new Vector3(Random.Range(targetMovePoint.x - 8f, targetMovePoint.x + 8f), 0f, Random.Range(targetMovePoint.z - 8f, targetMovePoint.z + 8f));

            targetMoveTimer = Random.Range(1.5f, 5f);
        }

        Vector3 toTarget = targetMovePoint - transform.position;

        if (toTarget.magnitude > 1f)
        {
            unitMover.Move(toTarget.normalized);
        }
    }
Beispiel #8
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        // Temp behavior: wander near origin
        targetMoveTimer = Mathf.MoveTowards(targetMoveTimer, 0f, Time.deltaTime);
        if (targetMoveTimer == 0f)
        {
            // Pick new target position
            targetMovePoint = new Vector3(Random.Range(-8f, 8f), 0f, Random.Range(-8f, 8f));

            targetMoveTimer = Random.Range(1.5f, 5f);
        }

        Vector3 toTarget = targetMovePoint - transform.position;

        if (toTarget.magnitude > 1f)
        {
            unitMover.Move(toTarget.normalized);
        }
    }